Submission #1005503

#TimeUsernameProblemLanguageResultExecution timeMemory
1005503anangoKitchen (BOI19_kitchen)C++17
100 / 100
29 ms1116 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { //freopen("input.txt","r", stdin); //freopen("output.txt","w",stdout); int n,m,k; cin >> n >> m >> k; int fail=0; vector<int> a,b; for (int i=0; i<n; i++) { int x; cin >> x; if (x<k) { fail=1; } a.push_back(x); } for (int i=0; i<m; i++) { int x; cin >> x; b.push_back(x); } if (fail) { cout << "Impossible" << endl; return 0; } sort(b.begin(), b.end()); int S = accumulate(b.begin(), b.end(), (int)0)+1; int T = accumulate(a.begin(), a.end(), (int)0); int dp[S]; for (int j=0; j<=S; j++) { dp[j] = -1; } dp[0] = 0; for (int i=0; i<m; i++) { int val = b[i]; for (int j=S; j>=val; j--) { if (dp[j-val]!=-1) { dp[j] = max(dp[j],dp[j-val]+min(n,val)); } } } int ans = -1; for (int i=T; i<=S; i++) { //cout << i <<" " << dp[i] << endl; if (dp[i]>=n*k) { ans=i-T; break; } } if (ans==-1) { cout << "Impossible" << endl; } else { cout << ans << 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...