传送门
http://www.lydsy.com/JudgeOnline/problem.php?id=3174
题目大意
一些人身体长
ai
手长
bi
用其中一些人并让某个人
i
在顶上使得
询问最大出去的人数
题解
长得高的人
(ai+bi大)
自救的机会更大所以尽量后出去
设计DP
dp[i]:
表示
i
个人出去后剩下的最大身体长的和
const
maxn=2005;
var
dp:array[0..maxn]of longint;
x:array[0..maxn,1..2]of longint;
i,j,k:longint;
n,m,ans:longint;
function max(a,b:longint):longint;
begin if a>b then exit(a) else exit(b); end;
procedure sort(l,r:longint);
var i,j,a,b,c:longint;
begin
i:=l; j:=r; a:=x[(l+r)div 2,1]+x[(l+r)div 2,2];
repeat
while (x[i,1]+x[i,2]<a) do inc(i);
while (x[j,1]+x[j,2]>a) do dec(j);
if not (i>j) then
begin
b:=1; c:=x[i,b]; x[i,b]:=x[j,b]; x[j,b]:=c;
b:=2; c:=x[i,b]; x[i,b]:=x[j,b]; x[j,b]:=c;
inc(i); dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
readln(n); dp[0]:=0;
for i:=1 to n do
begin
readln(x[i,1],x[i,2]);
inc(dp[0],x[i,1]);
dp[i]:=-1;
end;
sort(1,n); ans:=0; readln(m);
for i:=1 to n do
for j:=ans+1 downto 1 do
begin
if dp[j-1]+x[i,2]>=m
then dp[j]:=max(dp[j],dp[j-1]-x[i,1]);
if dp[j]<>-1 then ans:=max(ans,j);
end;
writeln(ans);
end.