Why my solution is giving wrong answer?

#include<bits/stdc++.h>
using namespace std;

int main() {
int t,n,m,ans=-1,diff=INT_MAX;
cin>>t;
for(int q=0;q<t;q++)
{
diff=INT_MAX;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
cin>>m;
for(int i=0;i<n;i++){
if(binary_search(arr,arr+n,m-arr[i]))
{
if(diff>abs(2arr[i]-m))
{
ans = arr[i];
diff = abs(2
arr[i]-m);
}
}
}
cout<<β€œDeepak should buy roses whose prices are β€œ<<ans<<” and β€œ<<m-ans<<”.”<<endl;
}
return 0;
}

Put diff >= abs( a-b).
Instead of diff> abs(2*A[I] -m)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.