March long Challenge 2021

Can be Solve this Space Arrays problem using this approach
Please Reply, is my approach is wrong or right ?
#include <bits/stdc++.h>
#define long long int;
using namespace std;
int main() {ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// solution comes here
int t;
cin>>t;
while(t–)
{int n;
cin>>n;
int sum=0,a;
for(int i=0;i<n;i++){
cin>>a;
sum+=a;
}
int summation=n*(n+1)/2;
if((summation-sum)<=0)
cout<<“Second”<<"\n";
else if((summation-sum)%2==1)
{
cout<<“First”<<"\n";
}
else
cout<<“Second”<<"\n";
}
return 0;
}

but my code is not passing all the cases
what is my mistake please reply

Consider the test case: 1 1 2 5 5
For above test case, summation = 5*6/2 = 15 & sum = 14,
Thus, as per your code, first person should win (as (summation-sum)%2==1) but it’s not the case here.
Here, second person will win because, no matter which element of array first person increments, there is no possible permutation that satisfies the condition a[i] <= p[i] for all valid ‘i’ (due to presence of two 5s initially).

Similar is for the case like say, 1 1 2 5 5 6 (here, we have two 5s).

(Note that I have written the test cases in sorted order but the ordering doesn’t matter, the result will still be same.)

So, you need to account for such cases as well and that will solve your problem. :slightly_smiling_face: