Pagini recente » Monitorul de evaluare | Cod sursa (job #1834367) | Cod sursa (job #530541) | Cod sursa (job #1335155) | Cod sursa (job #38892)
Cod sursa(job #38892)
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 j:integer;
begin
if i=0 then exit;
while (s+d[i]<=l)and(e[i]<b[i]) do
begin
s:=s+d[i];
e[i]:=e[i]+1;
end;
if s=l then
begin
q:=1;
exit;
end;
proc(i-1);
if q=1 then exit;
while e[i]>0 do
begin
s:=s-d[i];
e[i]:=e[i]-1;
proc(i-1);
if q=1 then exit;
end;
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.