Pagini recente » Cod sursa (job #602780) | Cod sursa (job #368218) | Cod sursa (job #46183)
Cod sursa(job #46183)
var a,b,d:array[1..50] of longint;
put:array[1..50] of int64;
l:int64;
n,c:longint;
function min(x,y:int64):int64;
begin
if x>y then
min:=y
else
min:=x;
end;
procedure citesc;
var i:longint;
f:text;
begin
assign(f,'shop.in'); reset(f);
read(f,n,c,l);
for i:=1 to n do
read(f,a[i],b[i]);
close(f);
end;
function calc(x:longint):int64;
var y:int64;
i:longint;
begin
y:=1;
for i:=1 to a[x] do
y:=y*c;
calc:=y;
end;
procedure solve;
var i,poz,j:longint;
nr_max:int64;
g:text;
begin
citesc;
for i:=1 to n do
put[i]:=calc(i);
while l<>0 do begin
nr_max:=-1;
poz:=0;
for j:=1 to n do
if (put[j]>nr_max) and (put[j]<l) and (b[j]<>0) then begin
nr_max:=put[j];
poz:=j;
end;
d[poz]:=min(l div (nr_max),b[poz]);
b[poz]:=b[poz]-d[poz];
l:=l-(d[poz]*nr_max);
end;
for i:=1 to n do
inc(l,d[i]);
assign(g,'shop.out'); rewrite(g);
writeln(g,l);
for i:=1 to n-1 do
write(g,d[i],' ');
writeln(g,d[n]);
close(g);
end;
begin
solve;
end.