0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 01:25:25 +00:00

CF294B Shaass and Bookshelf

R73175686
This commit is contained in:
Baoshuo Ren 2022-04-04 19:56:56 +08:00
parent 548a8a0683
commit 455f0aa2ca
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

39
Luogu/CF294B/CF294B.cpp Normal file
View File

@ -0,0 +1,39 @@
#include <cstring>
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 105;
int n, v[N], w[N], f[N * N], sum, ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i] >> w[i];
sum += v[i];
}
memset(f, 0x3f, sizeof(f));
f[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = sum; j >= v[i]; j--) {
f[j] = std::min(f[j], f[j - v[i]] + w[i]);
}
}
for (int i = sum; i >= 0; i--) {
if (f[i] <= sum - i) {
ans = sum - i;
break;
}
}
cout << ans << endl;
return 0;
}