#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define ordered_set tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>
const int N = 3e5+1;
const int MOD = 1e9+7;
void solve() {
int n;
cin >> n;
int a = 0,b=0;
int tie = 1;
vi x(n+1);
F(i,n) {
cin >> x[i];
if (x[i] == 1) a++;
else b++;
if (a == b) tie++;
}
cout << a sp b << endl;
cout << tie << endl;
int ans = 0;
a = b = 0;
for (int i=1;i<=n;i++) {
int c = 0,d=0;
for (int j=i;j<=n;j++) {
if (x[j] == 1) c++;
else break;
}
for (int j=i;j<=n;j++) {
if (x[j] == 2) d++;
else break;
}
if (a < b && a+c > b) ans = max(ans,c);
if (b < a && b+d > a) ans = max(ans,d);
if (x[i] == 1) a++;
else b++;
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
F(i,t) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |