Target sum pairs neelesh628

#include
using namespace std;
int main() {
int x,n,i;
int arr[100001]={0};
int count=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>x;
arr[x]++;

}
int target;
cin>>target;
for(i=1;i<=100000;i++)
{
    if(arr[i]>0 && arr[target-i]>0)
    {
        cout<<i<<" and "<<target-i<<endl;
        arr[target-i]=0;
        arr[i]=0;
    }
}
return 0;

}
can anybod help?
what is wrong in this code?

hi Neelesh
can you please save your code on the online ide

hey @neeleshr628, your appraoch is not working when numbers are negative.
Consider the case
6
-3
1
4
3
6
8
9
your output is
1 and 8
2 and 7
3 and 6
4 and 5
correct output is
1 and 8
3 and 6

still wrong answer. i have correct it for negative number too

hey @neeleshr628, you are saying that you have corrected it for negative numbers but it is still giving wrong answer for
6
-3
1
4
3
6
8
9

Listen this question is very simple. Consider this code for reference In case of further queries, please feel free to ask.