Pagini recente » Borderou de evaluare (job #1658135) | Cod sursa (job #2212934)
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int n = 0;
int best = 0;
int secondBest = 0;
int bestCandidate = 0;
void update() {
if (bestCandidate > best) {
secondBest = best;
best = bestCandidate;
} else if (bestCandidate > secondBest) {
secondBest = bestCandidate;
}
bestCandidate = 0;
}
int main() {
freopen("maxsecv.in", "r", stdin);
freopen("maxsecv.out", "w", stdout);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
if (x == 1) {
bestCandidate++;
} else {
update();
}
}
update();
printf("%d", best + secondBest);
return 0;
}