Cod sursa(job #1640991)

Utilizator PainfulBiscuitsVlad Ghionaru PainfulBiscuits Data 8 martie 2016 20:20:31
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 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;
    fin>>n>>k;
    sc=smax=-6000000;
    for(i=1;i<=n;i++)
    {
        fin>>x;
        if(sc<0)
        {
            sc=0;
            stc=i;
        }
        sc+=x;
        if(sc>smax)
        {
            smax=sc;
            drmax=i;
            stmax=stc;
        }
        if(drmax-stmax+1>=3)
            ok=1;
        else
            ok=0;
    }
    if(ok==1)
        fout<<stmax<<" "<<drmax<<" "<<smax;
    return 0;
}