Submission #423694

#TimeUsernameProblemLanguageResultExecution timeMemory
423694abdzagKitchen (BOI19_kitchen)C++17
100 / 100
49 ms1120 KiB
#include<bits/stdc++.h> #include<unordered_map> #define rep(i,a,b) for(int i=int(a);i<int(b);i++) #define rrep(i,a,b) for(int i=int(a);i>int(b);i--) #define trav(a,v) for(auto& a: v) #define sz(v) v.size() #define all(v) v.begin(),v.end() #define vi vector<int> typedef long long ll; typedef long double ld; typedef unsigned long long ull; const long long inf = 1e15; using namespace std; int main() { cin.sync_with_stdio(false); ll n, m, k; cin >> n >> m >> k; vector<ll> v(n); vector<ll> v2(m); rep(i, 0, n) { cin >> v[i]; if (v[i] < k) { cout << "Impossible" << endl; return 0; } } rep(i, 0, m)cin >> v2[i]; ll sum = 0; rep(i, 0, n)sum += v[i]; sort(all(v2), greater<>()); vector <ll>dp0(1e5,-inf); dp0[0]= 0;; ll ans = inf; ll sumv2 = 0; ll sumk = 0; rep(i, 0, m) { rrep(j, sumv2,-1) { dp0[j + v2[i]] = max(dp0[j + v2[i]], dp0[j] + min(n, v2[i])); } sumv2 += v2[i]; sumk++; } rep(i, sum, sumv2+1) { if (dp0[i] >= n * k) { ans = i; break; } } if (ans == inf)cout << "Impossible" << endl; else cout << ans - sum << endl; 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...