Cod sursa(job #3262259)

Utilizator teodor079Albert Teodor Stefan teodor079 Data 9 decembrie 2024 16:38:59
Problema Buline Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("buline.in");
ofstream g("buline.out");
int n,v[200005],mx,st,dr,l1,l2,stot,s1,s2;
bool clr;
int main()
{
    f>>n;
    for(int i=1; i<=n; i++)
    {
        f>>v[i]>>clr;
        if(!clr) v[i]*=-1;
        stot+=v[i];
    }
    cout<<stot;
    for(int i=1; i<=n; i++)
    {
        if(s1<0)
        {
            s1=v[i];
            l1=1;
        }
        else
        {
            s1+=v[i];
            l1++;
        }
        if(s2>0)
        {
            s2=v[i];
            l2=1;
        }
        else
        {
            s2+=v[i];
            l2++;
        }
        if(s1>mx)
        {
            mx=s1;
            st=i-l1+1;
            dr=l1;
        }
        if(stot-s2>mx)
        {
            mx=stot-s2;
            st=i+1;
            dr=n-l2;
        }
    }
    g<<mx<<' '<<st<<' '<<dr;
    return 0;
}