dp[i]表示第一队打饭时间i的最优解
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
struct Node{
int aa, bb;
}nd[205];
int n, sum[205], dp[40005], ans=0x3f3f3f3f;
bool cmp(Node x, Node y){
return x.bb>y.bb;
}
int main(){
cin>>n;
memset(dp, 0x3f, sizeof(dp));
for(int i=1; i<=n; i++)
scanf("%d %d", &nd[i].aa, &nd[i].bb);
sort(nd+1, nd+1+n, cmp);
for(int i=1; i<=n; i++) sum[i] = sum[i-1] + nd[i].aa;
dp[0] = 0;
for(int i=1; i<=n; i++){
for(int j=sum[i-1]; j>=0; j--){
dp[j+nd[i].aa] = min(dp[j+nd[i].aa], max(dp[j], j+nd[i].aa+nd[i].bb));
dp[j] = max(dp[j], sum[i]-j+nd[i].bb);
}
}
for(int i=1; i<=sum[n]; i++) ans = min(ans, dp[i]);
cout<<ans<<endl;
return 0;
}