Cod sursa(job #1152721)

Utilizator andreiblaj17Andrei Blaj andreiblaj17 Data 24 martie 2014 21:44:28
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
#include <deque>
#include <vector>
using namespace std;

#define nmax 50005
ifstream in("secv2.in");
ofstream out("secv2.out");

long long n,k,i,lo=1,hi,MAX=-1250000001,S=0,x;
long long s[nmax];

int main(){
    
    in >> n >> k;
    
    for (i=1; i<=n; i++){
        in >> x;
        
        s[i]=s[i-1]+x;
    }
    
    for (i=1; i<=n; i++)
        if (s[i]>=MAX && i>=k)
            MAX=s[i],
            hi=i;
    
    for (i=1; i<=hi; i++)
        if (s[hi]-s[i-1]>=MAX)
            MAX=s[hi]-s[i-1], lo=i;
    
    out << lo << " " << hi << " " << MAX << "\n";
    
    return 0;
}