getting the correct answer but not able to pass test case.
#include <bits/stdc++.h>
#include
using namespace std;
int main() {
int t;
cin>>t;
if(t>=1 && t<=100){
for(int a=0;a<t;a++){
string str;
int n;
cin>>n;
int price[n];
for(int x=0;x<n;x++){
cin>>price[x];
}
int m;
cin>>m;
getline(cin, str);
sort(price,price+n);
int i=0;
int j=n-1;
while(i<j){
int diff;
if(price[i]+price[j]>m){
j--;
}
else if(price[i]+price[j]<m){
i++;
}
else if(price[i]+price[j]==m){
if(price[j]-price[i]<=diff){
cout<<"Deepak should buy roses whose prices are "<<price[i]<<" and "<<price[j]<<"."<<endl;
break;
}
i++;
j--;
}
diff=price[j+1]-price[i-1];
}
}
}
return 0;
}