比赛 |
NOIP2008集训模拟1 |
评测结果 |
WWWAAAWAWW |
题目名称 |
地精贸易 |
最终得分 |
40 |
用户昵称 |
苏轼 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 09:22:48 |
显示代码纯文本
program cch(input,output);
var
i,n,m,tot,x,y,j,q,r,rp:longint;
a,b,c,v,tmp,ans:array[1..100] of longint;
ch:array[1..100] of real;
z:real;
begin
assign(input,'goblin.in');
assign(output,'goblin.out');
reset(input);
rewrite(output);
readln(n,m);
for i:=1 to m do
readln(a[i],b[i]);
tot:=0;
for i:=1 to m do
if a[i]<b[i] then
begin
x:=a[i];
y:=b[i]-a[i];
z:=y/x;
j:=tot;
while (j>0)and(ch[j]<z) do dec(j);
for q:=tot downto j+1 do
begin
ch[q+1]:=ch[q]; c[q+1]:=c[q]; v[q+1]:=v[q];
tmp[q+1]:=tmp[q];
end;
ch[j+1]:=z; c[j+1]:=x; v[j+1]:=y; tmp[j+1]:=i;
inc(tot);
end;
r:=n; rp:=0;
for i:=1 to tot do
begin
ans[tmp[i]]:=r div c[i];
rp:=rp+ans[tmp[i]]*(v[i]+c[i]);
r:=r mod c[i];
end;
inc(rp,r);
tot:=0;
for i:=1 to m do
if a[i]>b[i] then
begin
x:=b[i];
y:=a[i]-b[i];
z:=y/x;
j:=tot;
while (j>0)and(ch[j]<z) do dec(j);
for q:=tot downto j+1 do
begin
ch[q+1]:=ch[q]; c[q+1]:=c[q]; v[q+1]:=v[q];
tmp[q+1]:=tmp[q];
end;
ch[j+1]:=z; c[j+1]:=x; v[j+1]:=y; tmp[j+1]:=i;
inc(tot);
end;
r:=rp; rp:=0;
for i:=1 to tot do
begin
ans[tmp[i]]:=r div c[i];
rp:=rp+ans[tmp[i]]*(c[i]+v[i]);
r:=r mod c[i];
end;
inc(rp,r);
writeln(rp-n);
for i:=1 to m do
if ans[i]=0 then writeln('Buy 0')
else
if a[i]=b[i] then writeln('Buy 0')
else
if a[i]>b[i] then writeln('Buy ',ans[i],' from Horde')
else writeln('Buy ',ans[i],' from Alliance');
close(input);
close(output);
end.