Cod sursa(job #1203815)

Utilizator azkabancont-vechi azkaban Data 1 iulie 2014 12:54:38
Problema Secventa 2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <fstream>
using namespace std;
ifstream cin("secv2.in");
ofstream cout("secv2.out");

int n,i,sbest(-1<<19),aux,suma(0),sol1,sol2,k,Dq[60013],suma1,suma2,start,finish; 
int main () 
{ 
   cin>>n>>k;
   Dq[0]=0;
   for (i=1;i<=n;i++) cin>>Dq[i] , Dq[i]+=Dq[i-1];
   sbest=suma=Dq[k];
   finish=sol2=k;
   start=sol1=1;
   for(i=k+1; i<=n; i++ ) {
                            suma1=Dq[i]-Dq[i-k];
                            suma2=suma+Dq[i]-Dq[i-1];
                            if(suma<Dq[i]-Dq[i-1]) suma2-=suma;
                            if(suma1>suma2) sol1=i-k+1, sol2=i, suma=suma1;
                                                   else sol2=i, suma=suma2;
                            if(suma>sbest) sbest=suma , start=sol1 , finish=sol2;
                          }    
  cout<<start<<" "<<finish<<" "<<sbest;
return 0;
}