Submission #146720

#TimeUsernameProblemLanguageResultExecution timeMemory
146720VlatkoKitchen (BOI19_kitchen)C++14
100 / 100
61 ms1056 KiB
#include <bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif typedef long long ll; typedef pair<int, int> pii; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> a(n+1), b(m+1); int a_sum = 0, a_min = 1e5, b_sum = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; a_sum += a[i]; a_min = min(a_min, a[i]); } for (int i = 1; i <= m; ++i) { cin >> b[i]; b_sum += b[i]; } if (a_min < k || b_sum < a_sum) { cout << "Impossible\n"; return 0; } vector<int> pre(b_sum+1, -1e5), cur; pre[0] = 0; for (int i = 1; i <= m; ++i) { cur.assign(b_sum+1, -1e5); for (int h = 0; h <= b_sum; ++h) { if (h < b[i]) { cur[h] = pre[h]; } else { cur[h] = max(pre[h], pre[h - b[i]] + min(b[i], n)); } } swap(pre, cur); } int ans = 1e9; for (int h = a_sum; h <= b_sum; ++h) { if (pre[h] >= n*k) { ans = h - a_sum; break; } } if (ans == 1e9) { cout << "Impossible\n"; } else { cout << ans << '\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...