0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 01:18:47 +00:00
OI-codes/Codeforces/294/B/B.cpp

40 lines
686 B
C++
Raw Normal View History

2022-04-04 11:56:56 +00:00
#include <iostream>
2022-06-01 01:45:41 +00:00
#include <cstring>
2022-04-04 11:56:56 +00:00
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;
}