Cod sursa(job #185241)

Utilizator Mishu91Andrei Misarca Mishu91 Data 24 aprilie 2008 22:41:17
Problema Secventa 2 Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <cstdio>
#define MAX_N 50001

int N,K,V[MAX_N],A[MAX_N];

void read()
{
    scanf("%d %d",&N,&K);
    for(int i=0; i<N; i++)
        scanf("%d",V+i);
}

void solve()
{
    int x,ps = 0, pd = -1, max = 0;
    A[0] = V[0];
    for(int i=1; i<N; i++)
        if((((A[i] = A[i-1] + V[i]) > max) || pd == -1) && i >= K-1)
            max = A[i],pd = i;

    for(int i = pd - K+1; i>=0; --i)
        if((x = V[pd] - V[i]) > max)
            max = x,ps = i+1;

    printf("%d %d %d",ps+1,pd+1,max);
}

int main()
{
    freopen("secv2.in","r",stdin);
    freopen("secv2.out","w",stdout);
    read();
    solve();
}