Code is not working

the code works for example but fails for test case

below is the code:

#include

using namespace std;

void roses(long long int a[], int N, int M){
long long int ans[2];
long long int diff=1000000000;
for (int i=0;i<N;i++){
for (int j=i+1;j<N;j++){
if (a[i]+a[j]==M){
if (a[i]==a[j]){
ans[0]=a[i];
ans[1]=a[j];
}
else if (a[i]>a[j] && a[i]-a[j]<diff){
ans[0]=a[j];
ans[1]=a[i];
}
else if (a[j]>a[i] && a[j]-a[i]<diff){
ans[0]=a[i];
ans[1]=a[j];
}
}
}
}
cout<<"Deepak should buy roses whose prices are “<<ans[0]<<” and "<<ans[1]<<’.’<<endl;
}
int main() {
int T;
cin>>T;
int N;
int M;
for (int i=0;i<T;i++){
cin>>N;
long long int a[N];
for (int j=0;j<N;j++){
cin>>a[j];
}

	  cin>>M;
	  roses(a,N,M);
}
return 0;

}

The code has syntax errors in the cout statement and logical errors in handling the closest pair.

You can refer my code as well

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.