-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Flipping_Game.cpp
More file actions
67 lines (59 loc) · 1.45 KB
/
Copy pathA_Flipping_Game.cpp
File metadata and controls
67 lines (59 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Link: https://codeforces.com/problemset/problem/327/A
/*
||-------------------------------||
|| Mohiul Islam Miraz ||
||-------------------------------||
*/
#include <bits/stdc++.h>
#define swift \
ios_base::sync_with_stdio(0); \
cin.tie(NULL);
#define sac sort(v.begin(), v.end())
#define sdc sort(v.begin(), v.end(), greater<int>())
#define f1 bool flag = true
#define f0 bool flag = false
#define c0 int count = 0
#define c1 int count = 1
#define s0 long long sum = 0
#define a0 long long ans = 0
#define ll long long
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define minus cout << -1 << endl
#define cnt cout << count << endl
#define sm cout << sum << endl
using namespace std;
int main()
{
swift;
int t = 1;
// cin >> t;
while (t--)
{
int n; cin >> n;
vector<int>v(n);
for (int i = 0; i < n; i++) cin >> v[i];
int count1 = 0, extra0 = 0, extra0max = -1;
for (int i = 0; i < n; i++)
{
if (v[i] == 1)
{
count1 += 1;
if (extra0 > 0)
{
extra0 -= 1;
}
}
else
{
extra0 += 1;
if (extra0 > extra0max)
{
extra0max = extra0;
}
}
}
cout << count1 + extra0max << endl;
}
return 0;
}