Pagini recente » Cod sursa (job #1753786) | Cod sursa (job #1590539) | Cod sursa (job #2747887) | Cod sursa (job #2541557) | Cod sursa (job #39206)
Cod sursa(job #39206)
var a,ind:array[1..32]of integer;
b,d,e:array[1..32]of int64;
n,c,i,j,p,q,t:integer;
l,x,s:int64;
procedure Sort(l, r: Integer);
var
i, j, x, y: integer;
begin
i := l; j := r; x := a[(l+r) DIV 2];
repeat
while a[i] < x do i := i + 1;
while x < a[j] do j := j - 1;
if i <= j then
begin
y := a[i]; a[i] := a[j]; a[j] := y;
y := b[i]; b[i] := b[j]; b[j] := y;
y := ind[i]; ind[i] := ind[j]; ind[j] := y;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sort(l, j);
if i < r then Sort(i, r);
end;
procedure bouble;
var i,y,sch:longint;
begin
repeat
sch:=0;
for i:=1 to n-1 do
begin
if ind[i]>ind[i+1] then
begin
y:=a[i];
a[i]:=a[i+1];
a[i+1]:=y;
y:=b[i];
b[i]:=b[i+1];
b[i+1]:=y;
y:=ind[i];
ind[i]:=ind[i+1];
ind[i+1]:=y;
y:=e[i];
e[i]:=e[i+1];
e[i+1]:=y;
sch:=1;
end;
end;
until sch=0;
end;
procedure proc(i:integer);
var min:integer;
begin
if i=0 then exit;
min:=b[i];
if l div d[i]<min then min:=l div d[i];
e[i]:=min;
proc(i-1);
end;
begin
assign(input,'shop.in');
reset(input);
assign(output,'shop.out');
rewrite(output);
readln(n,c,l);
for i:=1 to n do
begin
ind[i]:=i;
readln(a[i],b[i]);
end;
sort(1,n);
q:=0;
x:=1;
p:=0;
for i:=1 to n do
begin
while p<a[i] do
begin
p:=p+1;
x:=x*c;
end;
d[i]:=x;
end;
proc(n);
bouble;
t:=0;
for i:=1 to n do t:=t+e[i];
writeln(t);
for i:=1 to n do write(e[i],' ');
close(output);
end.