记录编号 26492 评测结果 AAATTTTTTT
题目名称 准备工作 最终得分 30
用户昵称 Gravatar老虎小飞 是否通过 未通过
代码语言 Pascal 运行时间 7.021 s
提交时间 2011-07-24 16:49:20 内存使用 0.17 MiB
显示代码纯文本
var
f:array[0..100]of boolean;
p,r,d:array[0..100]of longint;
n,i,j,min,now,ans:longint;

procedure dfs(x:longint);
var
n0,m0,i:longint;
begin
    if x>n then begin
        if min<ans then ans:=min;
    end
    else begin
        n0:=now;m0:=min;
        for i:=1 to n do
            if not f[i] then begin
                if  r[i]>now then begin
                    if ans<r[i]+p[i]-d[i] then exit;
                end
                else begin
                    if ans<now+p[i]-d[i] then exit;
                end;
            end;
        for i:=1 to n do
            if not f[i] then begin
                f[i]:=true;
                if r[i]>now then now:=r[i];
                now:=now+p[i];
                if min<now-d[i] then min:=now-d[i];
                dfs(x+1);
                min:=m0;now:=n0;f[i]:=false;
            end;
    end;
end;

begin
    assign(input,'preparation.in');reset(input);
    assign(output,'preparation.out');rewrite(output);
    repeat
    read(n); ans:=200000000;min:=-20000000;
    if n=0 then break;
    for i:=1 to n do read(p[i]);
    for i:=1 to n do read(r[i]);
    for i:=1 to n do read(d[i]);
    dfs(1);
    writeln(ans);
    until n=0;
    close(input);close(output);
end.