Cod sursa(job #3274569)

Utilizator tomavladnicolae@gmail.comTomavlad [email protected] Data 7 februarie 2025 10:20:26
Problema Aprindere Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("maxsecv.in");
ofstream fout("maxsecv.out");
int n, mx1, mx2, cnt, a[1000003],sol;
int main()
{
    int i, x;
    fin >> n;
    for (i = 1; i <= n; i++)
    {
        fin >> a[i];
        if (a[i] == 1) cnt++;
        else cnt = 0;
        if (cnt > mx1)
        {
            sol = 1;
            mx1 = cnt;
        }
        else if (cnt == mx1) sol++;
    }
    if(sol>1)
    {
        fout<<mx1*2;
        return 0;
    }
    i = 1;
    while (i <= n)
    {
        cnt = 0;
        while (a[i] == 1)
        {
            i++;
            cnt++;
        }
        if (cnt != mx1) mx2 = max(mx2, cnt);
        i++;
    }
    fout<<mx1+mx2;
    return 0;
}