比赛 20110724 评测结果 AWTTTTTTTT
题目名称 准备工作 最终得分 10
用户昵称 Yoghurt 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-24 11:20:12
显示代码纯文本
{
Problem:
Arithmetic Analysis:
Writer:
Data:
Remark:
AC:
}
program preparation;
const
        filename='preparation';
        maxn=500;
var
        p,r,d,late,path:array[0..maxn] of longint;
        vis:array[0..maxn] of boolean;
        n,time,max,step,ans:longint;

procedure init;
var
        i:longint;
begin
        for i:=1 to n do read(p[i]);
        readln;
        for i:=1 to n do read(r[i]);
        readln;
        for i:=1 to n do read(d[i]);
        readln;
end;

procedure solve;
var
        time,max,i:longint;
begin
        time:=r[path[1]]+p[path[1]];
        late[1]:=time-d[path[1]];
        max:=0;
        for i:=2 to n do
        begin
                if time<r[path[i]] then time:=r[path[i]];
                time:=time+p[path[i]];
                late[i]:=time-d[path[i]];
                if late[i]>max then max:=late[i];
        end;
        if max<ans then ans:=max;
end;

procedure dfs(x:longint);
var
        i:longint;
begin
        inc(step);
        vis[x]:=true;
        path[step]:=x;
        if step=n then solve;
        for i:=1 to n do
                if not vis[i] then
                        dfs(i);
        dec(step);
        vis[x]:=false;
end;

procedure main;
var
        i:longint;
begin
        readln(n);
        while n<>0 do
        begin
                init;
                ans:=maxlongint;
                for i:=1 to n do
                begin
                        fillchar(vis,sizeof(vis),false);
                        step:=0;
                        dfs(i);
                end;
                writeln(ans);
                readln(n);
        end;
end;

begin
        assign(input,filename+'.in'); reset(input);
        assign(output,filename+'.out'); rewrite(output);

        main;

        close(input); close(output);
end.