Cod sursa(job #52338)

Utilizator infogodinfo god infogod Data 18 aprilie 2007 17:55:52
Problema Secventa 2 Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<fstream.h>
#include<limits.h>

long v[600];
long n, k;
long smax=LONG_MIN;

void citire()
{
  ifstream in("secv2.in");
  in>>n>>k;
  for (long i=1; i<=n; i++)
    in>>v[i];
  in.close();
}

void parcurs()
{
  long i, j, p;
  long l, lmax, s;
  for (i=1; i<n; i++)
    {
      s=0;
      l=0;
      for (j=i; j<=n; j++)
	{
	  s+=v[j];
	  l++;
	  if (l>=k)
	    {
	      if (s>smax)
		{
		  smax=s;
		  lmax=l;
		  p=j-l+1;
		}
	    }
	 }
    }
  ofstream out("secv2.out");
  out<<p<<" "<<p+lmax-1<<" "<<smax;
  out.close();
}


int main()
{
  citire();
  parcurs();
  return 0;
}