#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int worst = INT_MIN;
int best = INT_MAX;
int temp = best;
int cnt1 = 1; int cnt2 = 1;
for (int i = 0; i < n - 1; i++)
{
if (arr[i + 1] - arr[i] <= 2)
{
cnt1++;
worst = max(worst, cnt1);
}
if (arr[i + 1] - arr[i] > 2)
{
cnt1 = 1;
worst = max(worst, cnt1);
}
}
for (int i = 0; i < n - 1; i++)
{
if (arr[i + 1] - arr[i] <= 2)
{
cnt2++;
}
//best = min(best, cnt2);
if (arr[i + 1] - arr[i] > 2)
{
best = min(best, cnt2);
cnt2 = 1;
}
}
best = min(best, cnt2);
if (best == temp)
{
cout << n << " " << worst << endl;
}
else
cout << best << " " << worst << endl;
}
return 0;
}
Question
when i am running the testcases its showing answer but when i am running it in codechef it is throwing me SGTSTP error.Where am i doing wrong?