Cod sursa(job #1640985)

Utilizator PainfulBiscuitsVlad Ghionaru PainfulBiscuits Data 8 martie 2016 20:15:54
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
/*#include <fstream>*/
using namespace std;
/*ifstream fin("secv2.in");
ofstream fout("secv2.out");*/
int main()
{
    int n,k,i,x,ok,stc=1,sc=0,smax=0,stmax=1,drmax=0;
    cin>>n>>k;
    sc=smax=-6000000;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(sc<0)
        {
            sc=0;
            stc=i;
        }
        sc+=x;
        if(sc>smax)
        {
            smax=sc;
            drmax=i;
            stmax=stc;
        }
        if(drmax-stc+1>=3)
            ok=1;
        else
            ok=0;
    }
    if(ok==1)
        cout<<stmax<<" "<<drmax<<" "<<smax;
    return 0;
}