#include <stdio.h>
int main(){
int n, g, i;
scanf("%d\n", &n);
while(n--) {
int l = -1;
int c = 1;
scanf("%d", &g);
while(g--) {
scanf("%d", &i);
if (l == -1) l = i;
else if (i - 1 != l) break;
else l++;
c++;
}
fflush(stdin);
printf("%d\n", c);
}
}
I get all the outputs correctly, so I have no idea what could be wrong. On the other hand, Kattis accepts this code below that I found on GitHub, and the outputs are exactly the same as in my code. If anyone can explain to me what is wrong or why Kattis rejects my code I would appreciate it.
#include <bits/stdc++.h>
using namespace std;
int main()
{
//Initialize n and g, take in n
int n, g;
cin >> n;
//Iterate n times
while (n--)
{
//Take in g, initialize empty vector of size g
cin >> g;
vector<int> gnomes(g);
//Take in all the gnomes
for (int i = 0; i < g; i++) cin >> gnomes[i];
//Iterate through without the beginning or end since king won't be there
for (int i = 1; i < g-1; i++)
{
//Must break the order, and if you remove it the gnomes around it should be in order
if (gnomes[i] < gnomes[i-1] || gnomes[i] > gnomes[i+1] && gnomes[i-1] < gnomes[i+1])
{
//Output the 1 based index, so add 1
cout << i+1 << endl;
//And exit to the next group
break;
}
}
}
}