I couldnt able to pass the test cases

#include<bits/stdc++.h>
using namespace std;
int main() {
int n;cin>>n;
int a[n],i;for (i=0;i<n;i++) cin>>a[i];
int s;cin>>s;
map<int,int>m;
for (i=0;i<n;i++){
auto it=m.find(s-a[i]);
auto it1=m.find(a[i]);
if (it1!=m.end()) m[a[i]]++; else m[a[i]]=1;
if (it!=m.end()){
int x=m[s-a[i]];

    if (s-a[i]<=a[i])
    cout<<s-a[i]<<" "<<"and"<<" "<<a[i]<<endl;
    else
    cout<<a[i]<<" "<<"and"<<" "<<s-a[i]<<endl;
    
}
}
return 0;

}