Cod sursa(job #123418)
Utilizator | Popa-Matei Mihai Matei14 | Data | 15 ianuarie 2008 21:07:19 |
---|---|---|---|
Problema | Secventa 2 | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.51 kb |
#include<stdio.h>
int n,v[50000];
int main(){
int k,i,s=0,max,max2,p1,p2;
freopen("secv2.in","r",stdin);
freopen("secv2.out","w",stdout);
scanf("%d%d",&n,&k);
for(i=0;i<n;++i)
scanf("%d",&v[i]);
for(i=0;i<k;++i)
s+=v[i];
max=s;
p1=1;
p2=k;
for(i=k;i<n;++i){
s=s+v[i]-v[i-k];
max2=s;
for(int j=i+1;j<n;++j){
max2+=v[j];
if(max<max2){
max=max2;
p1=i-1;
p2=j+1;
}
}
}
printf("%d %d %d\n",p1,p2,max);
fclose(stdin);
fclose(stdout);
return 0;
}