Cod sursa(job #1136204)

Utilizator EuBossuletMuntea Andrei EuBossulet Data 8 martie 2014 22:01:57
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
using namespace std;

ifstream f("secv2.in");
ofstream q("secv2.out");

int j,x,n,k,i,s,aux1,hh,start,m=-26000;

int main()
{
        f>>n>>k;
        j=1;
        start=1;
        s=0;
        if (k==n){start=1; hh=n;}
        for (i=1;i<=n;i++)
        {
            f>>x;
            if (k==n){s=s+x;}
            else if (s<0){s=x;start=i;hh=i;}
            else{s=s+x; hh++;}
            if ((s>m) && (hh-start+1>=k)){m=s; aux1=start; j=hh; }
        }
        q<<aux1<<" "<<j<<" "<<m;
        f.close();
        q.close();
}