➤ Problem Link : OPCPIZZA
👉 Hint : Simple binary search approach using upper_bound and lower_bound in C++ STL
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { ll t; cin>>t; ll arr[100001]; while(t--) { ll n,m,ans=0; cin>>n>>m; for(int i=0;i<n;i++) cin>>arr[i]; sort(arr,arr+n); for(int i=0;i<n;i++) ans+=upper_bound(arr+i+1,arr+n,m-arr[i])-lower_bound(arr+i+1,arr+n,m-arr[i]); cout<<ans<<endl; } }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!