Submission #552012

#TimeUsernameProblemLanguageResultExecution timeMemory
552012ollelKitchen (BOI19_kitchen)C++14
100 / 100
69 ms1536 KiB
using namespace std; #include <bits/stdc++.h> #define rep(i,a,b) for(int i = a; i < b; i++) typedef vector<int> vi; typedef vector<vi> vvi; int n, m, k; vi a, b; int main() { cin >> n >> m >> k; a.resize(n); b.resize(m); rep(i,0,n) cin >> a[i]; rep(i,0,m) cin >> b[i]; rep(i,0,n) if (a[i] < k) { cout << "Impossible\n"; exit(0); } // dp[i] = num // dp[i] = maximum sum2 with sum1 = i? const int maxs = 330*330; vvi dp(2, vi(maxs, -1)); dp[0][0] = 0; dp[1][0] = 0; rep(i,0,m) { int sum1 = b[i]; int sum2 = min(b[i], n); int i1 = i&1; rep(j,0,maxs - sum1) { if (dp[i1][j] == -1) continue; dp[i1^1][j + sum1] = max(dp[i1^1][j + sum1], dp[i1][j] + sum2); dp[i1^1][j] = max(dp[i1^1][j], dp[i1][j]); } } int minimi = n * k; int start = 0; rep(i,0,n) start += a[i]; rep(i, start, maxs) { if (dp[0][i] >= minimi || dp[1][i] >= minimi) { cout << (i - start) << endl; exit(0); } } cout << "Impossible" << endl; }
#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...