Cod sursa(job #2212934)

Utilizator memecoinMeme Coin memecoin Data 15 iunie 2018 12:41:57
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#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;
}