Cod sursa(job #3369011)

Utilizator Tudor221Rotaru Tudor Tudor221 Data 17 octombrie 2026 09:57:57
Problema Litere Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("maxsecv.in");
ofstream fout("maxsecv.out");

int main() {
    int n;
    fin >> n;
    int lg_max1 = 0, lg_max2 = 0, lg = 0;
    for (int i = 0; i < n; i++) {
        int x;
        fin >> x;
        if (x == 1) {
            lg++;
        } else {
            lg = 0;
        }

        if (lg > lg_max1) {
            lg_max2 = lg_max1;
            lg_max1 = lg;
        } else if (lg > lg_max2) {
            lg_max2 = lg;
        }

    }

    fout << lg_max1 + lg_max2;

    return 0;
}