Cod sursa(job #1768664)

Utilizator GoogalAbabei Daniel Googal Data 1 octombrie 2016 12:12:25
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <fstream>

using namespace std;

ifstream fin("secv2.in");
ofstream fout("secv2.out");

int n,k,x,i,pc=1,sc,umax,pmax,smax;

int main()
{
    fin>>n>>k;
    for(i=1;i<=n;i++)
    {
        fin>>x;
        if(sc<0)
        {
            sc=0;
            pc=i;
        }
        sc+=x;
        if(sc>smax && i-pc+1>=k)
        {
            smax=sc;
            pmax=pc;
            umax=i;
        }
    }
    fout<<pmax<<' '<<umax<<' '<<smax;
    return 0;
}