Problem statement
CodeChef: Practical coding for everyone
The problem is that when N = 1, you’re not reading the input array and that element is being read as the N for the next test case. So, you’re reading in the test cases wrong.
2 Likes
Line 25: for(int i=1; i<=n-1; i++)
Should be for(int i=1; i<=n; i++)
Same with line 27.
Also, like others suggested about missed input, the if-else branching is a good practice but won’t be much useful as execution probably won’t enter the for loops, provided loops are written correctly.
1 Like
Move the
if(n==1)
{
cout<<"0"<<endl;
continue;
}
after the
for(int i=1; i<=n; i++) cin>>A[i];
otherwise you’ll miss reading in some input, and so end up reading in the wrong numbers!
Edit:
Beaten by @thatprakhar
5 Likes
Okay
Okay thankyou😑