Test cases not passing

tell problem in my code
#include
using namespace std;
int main() {
int n,a[1000];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int target;
target=a[n-1];
for(int j=0;j<n;j++)
{
for(int k=j+1;k<n;k++)
{
int left=j;
int right=k;
int sum=a[left]+a[right];
if(target==sum)
{
cout<<left<<“and”<<right<<endl;
left++;
right–;
}

        if(sum<target){
         left++;
        }
        if(sum>target){
        right--;
	}
}

}
}

Hey @prachi2521
This is your modified code. Try and understand it once. https://ide.codingblocks.com/s/180277
If your doubt is resolved after this please mark it as closed.

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.