比赛 |
NOIP2008集训模拟1 |
评测结果 |
AAAAAAATTT |
题目名称 |
地精贸易 |
最终得分 |
70 |
用户昵称 |
francis |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 09:33:30 |
显示代码纯文本
program goblin;
const
fin='goblin.in';
fou='goblin.out';
var
f:array[0..100000]of longint;
a:array[0..100000,1..100]of longint;
c:array[1..100,1..2]of longint;
num,w1,c1,w2,c2:array[1..100]of longint;
i,j,p,q,v,x,y,n1,n2,n,m:longint;
f1,f2:text;
procedure init;
begin
assign(f1,fin);
assign(f2,fou);
reset(f1); rewrite(f2);
read(f1,n,m);
for i:=1 to m do
begin
read(f1,x,y);
c[i,1]:=x; c[i,2]:=y;
if x<=y then begin inc(n1); w1[n1]:=x; c1[n1]:=y-x; end;
if x>y then begin inc(n2); w2[n2]:=y; c2[n2]:=x-y; end;
end;
end;
procedure change1;
begin
f[j]:=f[j-w1[i]]+c1[i];
for p:=1 to n1 do
a[j,p]:=a[j-w1[i],p];
inc(a[j,i]);
end;
procedure change2;
begin
f[j]:=f[j-w2[i]]+c2[i];
for p:=1 to n2 do
a[j,p]:=a[j-w2[i],p];
inc(a[j,i]);
end;
procedure main;
begin
v:=n;
for i:=1 to n1 do
for j:=1 to v do
if j-w1[i]>=0 then
if f[j-w1[i]]+c1[i]>f[j] then change1;
j:=0;
for i:=1 to m do
if c[i,1]<=c[i,2] then begin inc(j); num[i]:=a[v,j]; end;
v:=n+f[v];
for i:=1 to v do
begin
f[i]:=0;
for j:=1 to n2 do
a[i,j]:=0;
end;
for i:=1 to n2 do
for j:=1 to v do
if j-w2[i]>=0 then
if f[j-w2[i]]+c2[i]>f[j] then change2;
j:=0;
for i:=1 to m do
if c[i,1]>c[i,2] then begin inc(j); num[i]:=a[v,j]; end;
end;
procedure print;
begin
writeln(f2,f[v]+v-n);
for i:=1 to m do
begin
if num[i]=0 then writeln(f2,'Buy 0')
else begin
if c[i,1]<=c[i,2] then writeln(f2,'Buy ',num[i],' from Alliance');
if c[i,1]>c[i,2] then writeln(f2,'Buy ',num[i],' from Horde');
end;
end;
close(f1); close(f2);
end;
begin
init;
main;
print;
end.