比赛 NOIP2008集训模拟2 评测结果 AWWWWWWWWW
题目名称 阿鲁高的远航 最终得分 10
用户昵称 WaterFire 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-11 10:32:34
显示代码纯文本
program waterfire;
const
fin='sail.in';
fout='sail.out';
var
i,j,v,a,w,s,n,t:longint;
cost,data,day:array[0..1000] of longint;
f,g:text;

procedure print;
var
ii,jj:longint;
Begin
writeln(g,s);
for ii:=1 to t do
writeln(g,day[ii]);
close(g);
halt;
End;

Procedure work(x:longint);
var
ii,jj,c:longint;
Begin
 n:=0;ii:=0;jj:=0;c:=a;
 for ii:=x to t do
  begin
   if ii=x then
   begin
   inc(s,cost[ii]*data[ii]);
   day[x]:=data[ii]+day[x];
   end
       else if cost[x]*data[ii]+(ii-x)*w*data[ii]<cost[ii]*data[ii]
            then begin
               if  ((data[ii]+n)<v)and(c>data[ii]) then
               begin
               c:=c-data[ii];
               s:=s+cost[x]*data[ii]+w*(ii-x)*data[ii];
               n:=n+data[ii];
               day[x]:=n+day[x];
               end else
               if ((data[ii]+n)<v)and(c<data[ii]) then
               begin
               s:=s+cost[x]*c+c*w*(ii-x);
               data[ii]:=data[ii]-c;
               day[x]:=day[x]+c;
               work(ii);
               end else
               if ((data[ii]+n)>v)and(c<data[ii]) then
               if v-n>c then
               begin
               s:=s+cost[x]*c+c*w*(ii-x);
               data[ii]:=data[ii]-c;
               day[x]:=day[x]+c;
               work(ii);
               end else
               begin
               data[ii]:=data[ii]-(v-n);
               s:=s+cost[x]*(v-n)+w*(v-n)*(ii-x);
               day[x]:=v-n+day[x];
               n:=v;
               work(ii);
               end;
               end else work(ii);
    if ii=t then print;
  end;
End;
BEGIN
fillchar(day,sizeof(day),0);
assign(f,fin);reset(f);
assign(g,fout);rewrite(g);
readln(f,t,v,a,w);
for i:=1 to t do
 readln(f,data[i],cost[i]);
 close(f);
 work(1);
 END.