Cod sursa(job #1642167)

Utilizator RG1999one shot RG1999 Data 9 martie 2016 12:58:54
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <cstdio>

using namespace std;
int best[50005],n,k,x,lung[50005],i,max1,inmax,in,sf,sfmax;
int main()
{
    freopen("secv2.in","r",stdin);
    freopen("secv2.out","w",stdout);
    scanf("%d%d",&n,&k);
    lung [1]=1;
    max1=-(1<<30);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        best[i]=x;

        if(best[i]<best[i-1]+x)
           {
               best[i]=best[i-1]+x;
               lung[i]=lung[i-1]+1;
           }
           else
            if(i-1!=0)
            {
                if(best[i]>best[i-1]+x)
            {
                in=i;
                 lung[i]=1;

            }
            }
           else
            if(best[i]==best[i-1]+x)
                {
                    in=i;
                     lung[i]=1;
                }
         if(best[i]>max1&&lung[i]>=k)
         {
             max1=best[i];
             sfmax=i;
             inmax=in;
         }

    }
    printf("%d %d %d",inmax,sfmax,max1);

    return 0;
}