Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(NULL); cout.tie(NULL);
- int n; cin >> n; vector<int> a(n);
- for (int i=0; i<n; i++) cin >> a[i];
- int MinIndex = 0, MaxIndex = 0;
- int CurrMin = 0, CurrMax = 0;
- for (int i=0; i<n; i++) {
- if (a[i] == 0) {
- CurrMin++; CurrMax++;
- CurrMin = min(CurrMin, 0);
- }
- else {
- CurrMin--; CurrMax--;
- CurrMax = max(CurrMax, 0);
- }
- MinIndex = min(MinIndex, CurrMin);
- MaxIndex = max(MaxIndex, CurrMax);
- }
- cout << (MaxIndex - MinIndex + 1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement