题目地址:http://codevs.cn/problem/1052/
分析:
动态规划
代码:
var f,que,p:array[0..100]of longint;
t:array[1..100]of longint;
maxtime,mintime,i,j,n,pre,cur:longint;
flag:array[1..100]of boolean;
procedure qsort(h,ta:longint);
var ii,jj,mid,k:longint;
begin
ii:=h;
jj:=ta;
mid:=t[(h+ta) div 2];
repeat
while t[ii]<mid do inc(ii);
while t[jj]>mid do dec(jj);
if ii<=jj then begin
k:=t[ii];
t[ii]:=t[jj];
t[jj]:=k;
k:=p[ii];
p[ii]:=p[jj];
p[jj]:=k;
inc(ii);
dec(jj);
end;
until ii>jj;
if h < jj then qsort(h,jj);
if ii < ta then qsort(ii,ta);
end;
begin
readln(n);
for i := 1 to n do read(t[i]);
for i := 1 to n do read(p[i]);
qsort(1,n);
maxtime:=t[n];
mintime:=t[1];
fillchar(flag,sizeof(flag),true);
for i := maxtime downto 1 do begin
pre:=0;
cur:=0;
for j := 1 to n do if (t[j]>=i)and(flag[j]=true) then begin
inc(pre);
que[pre]:=j;
end;
for j := 1 to pre do if p[que[j]]>p[cur] then cur:=que[j];
if cur <> 0 then begin
flag[cur]:=false;
f[i]:=f[i]+p[cur];
end;
f[i-1]:=f[i];
end;
writeln(f[1]);
end.