Submission #958375

#TimeUsernameProblemLanguageResultExecution timeMemory
958375NomioKitchen (BOI19_kitchen)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; int a[n], b[m]; bool w = 1; for(int i = 0; i < n; i++) { cin >> a[i]; if(a[i] < k) { w = 0; } } for(int i = 0; i < m; i++) { cin >> b[i]; } if(!w || m < k) { cout << "Impossible" << "\n"; return 0; } bool dp[301] {}; dp[0] = 1; for(int i = 0; i < m; i++) { for(int j = 0; j <= 300; j++) { if(dp[j] && j + b[i] <= 300) { dp[j + b[i]] = 1; } } } vector<int> v; for(int i = 1; i <= 300; i++) { if(dp[i]) v.push_back(i); } int S = 0; for(int i = 0; i < n; i++) { if(v.back() < a[i]) { cout << "Impossible" << "\n"; return 0; } int x = upper_bound(v.begin(), v.end(), a[i]) - v.begin(); if(v[x - 1] != a[i]) { S += (v[x] - a[i]); } } cout << S << "\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...