Cod sursa(job #309375)

Utilizator 7RaduRadu Antohi 7Radu Data 30 aprilie 2009 10:13:45
Problema Carnati Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.79 kb
program Carnati;
var
   n,m,c,i,j,k,s,mn,i1,max1,j1,tt,ss,sst,mm,inc1,inc2:longint;
   t,p:array[0..2000] of longint;
   fl:text;
begin
  assign(fl,'carnati.in');
  reset(fl);
  readln(fl,n,c);
  for i := 1 to n do
     readln(fl,t[i],p[i]);
  close(fl);

  s:=0;
  tt:=0;
  mm:=0;
  for i := 1 to n do
     begin
        mm:=0;
        for j := 1 to n do
           begin
              if p[j]>=p[i] then
                 i1:=p[i]
              else
                 i1:=0;

              ss:=i1+mm-(t[j]-t[j-1])*c;

              if ss<i1-c then
                 ss:=i1-c;

              if ss>max1 then
                 max1:=ss;
              mm:=ss;
           end;
     end;
   assign(fl,'carnati.out');
   rewrite(fl);
   writeln(fl,max1);
   close(fl);
end.