Cod sursa(job #2342173)

Utilizator vladuteluVlad Oancea vladutelu Data 12 februarie 2019 17:22:42
Problema Secventa 2 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <bits/stdc++.h>
using namespace std;

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

int main()
{
    int n, k, smax = 0, s = 0, curIc = 1, sf = 1, x, ic = 1;
    in>>n>>k;
    for(int i = 1; i<=n; i++)
    {
        in>>x;
        s+=x;
        if(s>smax && i-curIc+1>=k)
        {
            smax = s;
            sf = i;
            ic = curIc;
        }
        if(s<0)
        {
            s = 0;
            curIc = i + 1;
        }
    }
    out<<ic<<" "<<sf<<" "<<smax;
    return 0;
}