#include <bits/stdc++.h>
using namespace std;
bool sortbysecdesc(const pair<int,int> &a,
const pair<int,int> &b)
{
return a.second > b.second;
}
int main()
{
int n;
cin >> n;
int seq[n];
for(int i = 0; i < n; i++)
cin >> seq[i];
vector < pair <int,int> > depths;
vector < pair <int,int> > symbols;
int i = 0;
int pos, j, c, s, d;
while(i < n)
{
c = 0;
s = 0;
pos = i;
while(seq[i] == 1)
{
c++;
s++;
i++;
}
d = c;
j = i;
while(c != 0)
{
if(seq[j] == 2)
{
s++;
c--;
}
else
{
s++;
c++;
}
j++;
}
depths.push_back(make_pair(pos+2, d));
symbols.push_back(make_pair(pos+1, s));
i = j;
}
sort(depths.begin(), depths.end(), sortbysecdesc);
sort(symbols.begin(), symbols.end(), sortbysecdesc);
cout << depths[0].second << " " << depths[0].first << " " << symbols[0].second << " " << symbols[0].first << "\n";
return 0;
}
I have coded the above solution for ZCO12001 and it does work when I run it offline using an IDE and it also works in case of custom input on CodeChef but RUN returns SIGTSTP and on submitting I get WA for all the test cases. Please help. Where am I going wrong? I have tried it with multiple sample test cases (that I generated on my own) and it works on all of them but fails every time on Submitting.