Cod sursa(job #308380)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 26 aprilie 2009 22:20:52
Problema Secventa 2 Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include<fstream.h>   
long long a[501],u,k,z,n,i,c,y,s,yy,x,xx,max;
int main()   
{   
ifstream f("secv2.in");   
ofstream g("secv2.out");   
f>>n>>k;   
s=0;   
max=-200000000;
z=1;
for (i=1;i<=n;i++)   
    {
    u=a[i];
    f>>a[i];

    if (s<0 && i-z+1>k){s=a[i];z=i;s-=u;}
    else s=s+a[i];

    if(max<s&&i-z+1>=k){max=s;if (a[z]<0&&s>0)xx=z-1;else if(a[z-1]>0) xx=z-1;else xx=z; yy=i;}
    }
max=0;
for (i=xx;i<=yy;i++)
    max+=a[i];
g<<xx<<' '<<yy<<' '<<max<<'\n';   
g.close();   
return 0;   
}