Submission #1106528

#TimeUsernameProblemLanguageResultExecution timeMemory
1106528cot7302Kitchen (BOI19_kitchen)C++17
100 / 100
17 ms592 KiB
#include <bits/stdc++.h> #define ALL(X) begin(X), end(X) using namespace std; using i64 = long long; template <class T> using vec = vector<T>; template <class T> istream& operator>>(istream& is, vec<T>& V) { for (auto& x : V) is >> x; return is; } constexpr int inf = 1'000'000'000; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; if (m < k) return cout << "Impossible\n", 0; int sum_a{}; for (int i = 0; i < n; i++) { int x; cin >> x; if (x < k) return cout << "Impossible\n", 0; sum_a += x; } vec<int> b(m); cin >> b; int sum_b = reduce(ALL(b)); vec<int> dp(sum_b + 1, -inf); dp[sum_b] = 0; for (auto x : b) { for (int w = 0; w + x <= sum_b; w++) dp[w] = max(dp[w], dp[w + x] + min(x, n)); } for (int i = sum_a; i <= sum_b; i++) if (dp[sum_b - i] >= n * k) return cout << i - sum_a << '\n', 0; cout << "Impossible\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...