Cod sursa(job #2068554)

Utilizator AlexPop28Pop Alex-Nicolae AlexPop28 Data 18 noiembrie 2017 09:13:38
Problema Secventa 2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <iostream>
#include <climits>
#include <fstream>
using namespace std;
ifstream fin ("secv2.in");
ofstream fout ("secv2.out");
int n,k,i,x,maxx = INT_MIN,st,stf,drf;
long long s,stot;
int main()
{
    cout << maxx;
    fin >> n >> k;
    st=1;
    for(i=1; i<=n; i++)
    {
        fin >> x;
        if(s<0)
        {
            s=x;
            st=i;
        }
        else
            s=s+x;
        if(s>maxx && i-st+1>=k)
        {
            stf=st;
            drf=i;
            maxx=s;
        }

        stot+=x;
    }

    if(k==n)
        fout << 1 << " " << n << " " << stot;
    else
    {
        fout << stf << " " << drf << " " << maxx ;
    }

    return 0;
}