Cod sursa(job #1174054)

Utilizator azkabancont-vechi azkaban Data 21 aprilie 2014 21:02:10
Problema Lupul Urias si Rau Scor 16
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.02 kb
Program hep_lup;
var n,k,i,a,b,m,max,suma,pivot : longint;
    H,L : array [0..100000] of longint;
begin
    assign(input,'lupu.in'); reset(input);
    assign(output,'lupu.out'); rewrite(output);
    readln(m,n,k);
    for i:=0 to n do H[i]:=n-i+1;
    for i:=1 to m do begin
                          readln(a,b);
                          if L[a]<b then L[a]:=b;
                          suma:=suma+b;
                     end;
if k=0 then writeln(suma)
        else begin
                   suma:=0;
                   pivot:=n;
                   while pivot>=0 do begin
                                         max:=0;
                                          for i:=pivot downto pivot-k+1 do
                                            if max<L[i] then max:=L[i];
                                         pivot:=pivot-k;
                                         suma:=suma+max;
                                     end;
                   writeln(suma);
             end;
    close(input); close(output);
end.