Cod sursa(job #2199110)

Utilizator RaduVFVintila Radu-Florian RaduVF Data 26 aprilie 2018 18:02:07
Problema Secventa 2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
long long s,mx=INT_MIN;
int x,j,n,k,p=1,u,all,pg,ug;
int main()
{
    fin>>n>>k;
    for(int i=1; i<=n; i++){
        fin>>x;
        if (s>=0)
            s+=x;
        else{
            s=x;
            p=i;
        }
        if (s>mx && i-p+1>=k){
            ug=i;
            mx=s;
            pg=p;
        }
        all+=x;
    }
    if (k==n) fout<<"1 "<<n<<' '<<all;
    else fout<<pg<<" "<<ug<<" "<<mx;
    return 0;
}