记录编号 129509 评测结果 AAAAAAAAAA
题目名称 支付宝 最终得分 100
用户昵称 GravatarWW TT 是否通过 通过
代码语言 Pascal 运行时间 0.346 s
提交时间 2014-10-20 06:56:16 内存使用 6.57 MiB
显示代码纯文本
var
   nn,vv:array[1..20000] of longint;
   v:array[1..400000] of longint;
   num:array[1..400000] of int64;
   f:array[0..20000] of longint;
   yl:array[1..400000] of longint;
   use:array[1..20000] of longint;
   te,tail,mon,n,hx,i,j,k,ans:longint;
procedure init;
begin
readln(n);
for i:=1 to n do
read(vv[i]);
readln;
for i:=1 to n do
read(nn[i]);
readln(mon);
tail:=0;
for i:=1 to n do
begin
te:=1;
while nn[i]>te do
begin
nn[i]:=nn[i]-te;
inc(tail);
v[tail]:=vv[i]*te;
num[tail]:=te;
yl[tail]:=i;
te:=te*2;
end;
inc(tail);
v[tail]:=vv[i]*nn[i];
num[tail]:=nn[i];
yl[tail]:=i;
end;
for i:=1 to 20000 do f[i]:=maxlongint;
for i:=1 to tail do
 for j:=mon downto v[i] do
 if f[j]>f[j-v[i]]+num[i] then f[j]:=f[j-v[i]]+num[i];
te:=mon;
while te<>0 do
for i:=tail downto 1 do
begin
if te=0 then break;
if (te>=v[i])and(f[te-v[i]]+num[i]=f[te])
then
begin
inc(use[yl[i]],num[i]);
te:=te-v[i];
end;
end;
end;

begin
assign(input,'pay.in');
reset(input);
assign(output,'pay.out');
rewrite(output);
init;
writeln(f[mon]);
for i:=1 to n do
write(use[i],' ');
close(output);
end.