Cod sursa(job #575945)

Utilizator paul_gabryelPaul Buda paul_gabryel Data 8 aprilie 2011 23:09:09
Problema Secventa 2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb

#include <cstdio>
#include <fstream>

using namespace std;

#define inf 1<<30
#define N 1<<16

int main ()
{

    int s[N];
    s[0]=0;
    int n,k;
    ifstream in ("secv2.in");
    freopen ("secv2.out","w",stdout);
    in>>n>>k;
    for(int i=1;i<=n;++i){
        in>>s[i];
        s[i]+=s[i-1];
    }
    pair<int,int> ind;
    int m=inf,M=-inf;
    for(int i=k;i<=n;++i){
        if(s[i-k]<m){
            m=s[i-k];
            ind.first=i-k+1;
        }
        if(s[i]-m>M){
            M=s[i]-m;
            ind.second=i;
        }
    }
    printf("%d %d %d\n",ind.first,ind.second,M);

return 0;}