Submission #122998

#TimeUsernameProblemLanguageResultExecution timeMemory
122998model_codeKitchen (BOI19_kitchen)C++17
100 / 100
68 ms760 KiB
//Author: Oliver-Matis Lill //O(N M B_max) DP solution. Finds maximum "diversity box filled" for a given total hour count #include<iostream> #include<vector> #include<numeric> #include<algorithm> using namespace std; const int INF = 1000000000; int sum(vector<int> &a) { return accumulate(a.begin(), a.end(), 0); } int min(vector<int> &a) { return *min_element(a.begin(), a.end()); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> A(n), B(m); for(int i=0; i<n; i++) { cin >> A[i]; } for(int i=0; i<m; i++) { cin >> B[i]; } if(min(A) < k) { cout << "Impossible\n"; return 0; } vector<int> dp((m+1)*301, -1); dp[0] = 0; for(int i=0; i<m; i++) { for(int j=dp.size()-B[i]-1; j >= 0; j--) { if(dp[j] != -1) { dp[j+B[i]] = max(dp[j+B[i]], dp[j] + min(B[i], n)); } } } int result = INF; int a_sum = sum(A); for(int j=a_sum; j<(int)dp.size(); j++) { if(dp[j] >= n*k) { result = min(result, j - a_sum); } } if(result == INF) { cout << "Impossible\n"; } else { cout << result << '\n'; } return 0; }
#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...