#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1000005;
const int INF = 0x3f3f3f3f;
#define reg register
#define IOS ios::sync_with_stdio(false)
int n;
int V[MAXN];
int W[MAXN];
int dp[100000];
int m;
void solve() {
memset(dp, INF, sizeof(dp));
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = m; j >= V[i]; j--) {
dp[j] = min(dp[j], dp[j - V[i]] + W[i]);
}
}
for (int i = m; i >= 0; i--) {
if (dp[i] <= m - i) {
printf("%d", m - i);
return ;
}
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", V + i, W + i);
m += V[i];
}
solve();
return 0;
}
CF294B Shaass and Bookshelf (01背包变形)
于 2022-03-25 14:33:01 首次发布