Pagini recente » Cod sursa (job #397710) | Cod sursa (job #257995) | Cod sursa (job #2598933) | Cod sursa (job #1909429) | Cod sursa (job #1174084)
Program hep_lup;
var n,k,i,a,b,j,m,max,suma,pivot : longint;
L,Viz,H : array [0..300000] of longint;
b1,b2 : array [0..1 shl 17] of char;
procedure swap(var x,y : longint);
var aux : longint;
begin
aux:=x;
x:=y;
y:=aux;
end;
procedure qsort ( left,right : longint);
var i,j,pivot : longint;
begin
i:=left; j:=right; pivot:=L[(left+right) div 2];
repeat
while L[i]>pivot do i:=i+1;
while L[j]<pivot do j:=j-1;
if i<=j then begin
swap(L[i],L[j]);
swap(H[i],H[j]);
i:=i+1;
j:=j-1;
end;
until i>j;
if i<right then qsort(i,right);
if j>left then qsort(left,j);
end;
begin
assign(input,'lupu.in'); settextbuf(input,b1); reset(input);
assign(output,'lupu.out'); settextbuf(output,b2); rewrite(output);
readln(m,n,k);
for i:=1 to m do begin
readln(a,b);
L[i]:=b;
H[i]:=a;
end;
qsort(1,m);
for i:=1 to m-1 do
for j:=i+1 to m do
if (L[i]=L[j]) and (H[i]<H[j]) then swap(H[i],H[j]);
pivot:=n;
for i:=1 to m do
if H[i]<=pivot then begin
suma:=suma+L[i];
pivot:=pivot-k;
end;
writeln(suma);
close(input);
close(output);
end.