Cod sursa(job #54018)

Utilizator me_andyAvramescu Andrei me_andy Data 23 aprilie 2007 21:57:09
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include<fstream.h>

 long s,c,smax,b,x,q,x2,x3;
  int a[50000];
  long i,j;
  ifstream f("secv2.in");
  ofstream g("secv2.out");

int main()
{
 f>>x;
 f>>b;
 s=0;
 c=0;
 smax=-1250000000;
 x3=0;
 x2=0;
 for(i=1;i<=x;i++)
  f>>a[i];
 for(j=1;j<=x-b;j++)
  for(q=x;q>=b;q--)
 {c=0;
  for(i=j;i<=q;i++)
     s=s+a[i];
   if(s>smax)
   {
    smax=s;
    x3=q;
    x2=j;
   } 
}              
 g<<x3<<" "<<x2<<" "<<smax;
 f.close();
 g.close();
 return 0;

}