From 455f0aa2ca31044b4d7ad6e881740e3ce7803dca Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 4 Apr 2022 19:56:56 +0800 Subject: [PATCH] CF294B Shaass and Bookshelf R73175686 --- Luogu/CF294B/CF294B.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Luogu/CF294B/CF294B.cpp diff --git a/Luogu/CF294B/CF294B.cpp b/Luogu/CF294B/CF294B.cpp new file mode 100644 index 00000000..d3ad2595 --- /dev/null +++ b/Luogu/CF294B/CF294B.cpp @@ -0,0 +1,39 @@ +#include +#include + +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; +}