The is running absolutely fine if I am providing custom inputs but when I submit it rejects it. I have nearly given one day on this single problem.
Please suggest what can be done.
Here goes my code::
#include
#include<bits/stdc++.h>
using namespace std;
int main() {
int a[1000];
int n, target, sum=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cin>>target;
int i=0;
int l=1;
int r=n-1;
sort(a, a+n);
for(i=0;i<n;i++)
{
while(l<r)
{
//cout<<“I entered while loop”<<endl;
sum = a[i]+a[l]+a[r];
cout<<sum<<endl;
if(sum == target)
{
cout<<a[i]<<", “<<a[l]<<” and "<<a[r]<<endl;
l+=1;
r-=1;
//cout<<“i am in sum == target”<<endl;
}
else if(sum > target)
{
r-=1;
//cout<<“i am checking sum>target”<<endl;
}
/*if((l+1==r) || (l>r))
{
i+=1;
r=n-1;
l=i+1;
cout<<"I am checking l == r"<<endl;
}*/
// r-=1;
// l+=1;
// i+=1;
// cout<<“i decrement r”<<endl;
}
i++;
r=n-1;
l=i+1;
}
return 0;
}
with Regards
Yash
