Cod sursa(job #159546)

Utilizator IoNu-Velciu Ionut IoNu- Data 14 martie 2008 11:07:00
Problema Carnati Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.31 kb
var f,g:text;
    n,i,j,k,u:word;
    c:longint;
    s,max,aux,x:longint;
    t:array[1..2000] of 1..1500;
    p:array[1..2000] of longint;
begin
     assign(f,'carnati.in');
     reset(f);
     assign(g,'carnati.out');
     rewrite(g);
     read(f,n); readln(f,c);
     for i:=1 to n do
         begin
              read(f,t[i]);
              readln(f,p[i]);
         end;
     for i:=1 to n-1 do
         for j:=i+1 to n do
             if t[i]>t[j] then
                begin
                     aux:=t[i];
                     t[i]:=t[j];
                     t[j]:=aux;
                     aux:=p[i];
                     p[i]:=p[j];
                     p[j]:=aux;
                end;
     max:=0;
     for i:=1 to n-1 do
         for j:=i+1 to n do
             begin
                  for u:=i to j do
                      begin
                           x:=p[u];
                           s:=0;
                           for k:=i to j do
                               begin
                                    if p[k]>=x then s:=s+x;
                               end;
                           s:=s-(t[j]-t[i]+1)*c;
                           if s>max then begin max:=s; end;
                      end;
             end;
     write(g,max);
     close(f);
     close(g);
end.