Cod sursa(job #1642151)

Utilizator RG1999one shot RG1999 Data 9 martie 2016 12:55:15
Problema Secventa 2 Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 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;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        best[i]=x;
        if(best[i-1]+best[i]>best[i])
            {
                best[i]=best[i-1]+best[i];
                lung[i]=lung[i-1]+1;
            }
            else
              if(i-1!=0)
             if(best[i-1]+best[i]<best[i-1])
           {
               lung[i]=1;
               best[i]=best[i-1];
               in=i;
           }

           if(best[i]>max1&&lung[i]>=k)
           {
               max1=best[i];
               inmax=in;
               sfmax=i;
           }

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

    return 0;
}