Cod sursa(job #2339018)

Utilizator stefandutastefandutahoria stefanduta Data 8 februarie 2019 11:44:42
Problema Secventa 2 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("secv2.in");
ofstream out("secv2.out");
int n,k,i,x,maxx =-20000000,st,stf,drf;
int main()
{
    long long s=0,smax=0;
    in>>n>>k;
    st=1;
    for(i=1;i<=n;i++)
    {
        in>>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;
        }
        smax+=x;
    }
    if(k==n)
        out<<1<<" "<<n<<" "<<smax;
    else
    {
        out<<stf<< " " <<drf<<" "<<maxx;
    }
    return 0;
}