Test cases not passing

#include
#include
using namespace std;
int main() {
int n,i,key,p,q,sum;
cin>>n;
int a[1000];
for (i=1;i<=n;i++){
cin>>a[i];
}
cin>>key;
sort (a,a+n);
p=0;
q=n-1;
while(p<q){
sum=a[p]+a[q];
if (sum==key){
cout<<a[p]<<" and "<<a[q]<<endl;;
p++;
q–;
}
else if (sum>key){
q–;
}
else {
p++;
}
}

return 0;

}
only test case 0 is passing although output is coming out to be correct

hello @pranaynigam

here start i from 0 and go till i <n


still not working

check now=>

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.