Cod sursa(job #1152691)

Utilizator andreiblaj17Andrei Blaj andreiblaj17 Data 24 martie 2014 21:33:49
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");

int n,k,i,lo=1,hi,MAX=-nmax,S=0;
int v[nmax],s[nmax];

int main(){
    
    in >> n >> k;
    
    for (i=1; i<=n; i++){
        in >> v[i];
        
        s[i]=s[i-1]+v[i];
    }
    
    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;
}