Cod sursa(job #137529)

Utilizator bacerandreiBacer Andrei bacerandrei Data 17 februarie 2008 12:33:53
Problema Carnati Scor 10
Compilator cpp Status done
Runda preONI 2008, Runda 4, Clasa a 10-a Marime 0.88 kb
#include<fstream.h>
long long n,c,t[2000],p[2000],i,j,k,profit,max,x;



void quik(long long p1,long long q)
{
  long long aux,i,j,t1;
   if(p1<q)
    {
     i=p1;
     j=q;
     t1=1;
      do
       {
	if(t[i]>t[j])
	 {
	  aux=t[i];
	  t[i]=t[j];
	  t[j]=aux;
	  aux=p[i];
	  p[i]=p[j];
	  p[j]=aux;
	  t1=!t1;
	 }
       if(t1)
	j--;
       else
	i++;
      }while(i!=j);
   quik(p1,i-1);
   quik(i+1,q);
  }
}


int main()
{
  ifstream f("carnati.in");
  ofstream g("carnati.out");
   f>>n>>c;
  for(i=1;i<=n;i++)
   f>>t[i]>>p[i];
  i=1;
   while(i<=n-1)
    {
     j=i+1;
      while(j<=n)
       {
	for(k=i;k<=j;k++)
	 {
	  profit=0;
	   for(x=i;x<=j;x++)
	    if(p[x]>=p[k])
	     profit+=p[k];
	   profit=profit-(t[j]-t[i]+1)*c;
	    if(profit>max)
	     max=profit;
	  }
	j++;
       }
      i++;
     }
   g<<max;
  return 0;
}