Cod sursa(job #2666887)

Utilizator lenkkaPana Luca lenkka Data 2 noiembrie 2020 16:18:14
Problema Secventa 2 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>

using namespace std;

int main()
{
    ifstream fin("secv2.in");
    ofstream fout("secv2.out");
    int n,k;
    fin >> n >> k;
    long long sc=0,smax=-9223372036854775807;
    int drmax=1,st=1,stmax=1,lc=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        fin >> x;
        lc++;
        if(sc<0)
        {
            sc=0;
            st=i;
	    lc=0;
        }
        sc +=x;
        if(sc>smax && lc>=k)
        {
            smax=sc;
            drmax=i;
            stmax=st;
        }
    }
    fout << stmax << " " << drmax << " " << smax;
    fout.flush();
    return 0;
}