Submission #464302

#TimeUsernameProblemLanguageResultExecution timeMemory
464302JovanBKitchen (BOI19_kitchen)C++17
100 / 100
29 ms1044 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 300; int a[N+5]; int dp[N*N+5]; int mxm[N*N+5]; const int INF = 1000000000; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, m, k; int tot = 0; cin >> n >> m >> k; for(int i=1; i<=n; i++){ cin >> a[i]; tot += a[i]; if(a[i] < k){ cout << "Impossible\n"; return 0; } } vector <int> small, large; for(int i=1; i<=m; i++){ int x; cin >> x; if(x >= n) large.push_back(x); else small.push_back(x); } for(auto x : small) for(int i=N*N; i>=x; i--) if(dp[i-x] == i - x) dp[i] = i; dp[N*N+1] = INF; for(int i=N*N; i>=1; i--) if(dp[i] != i) dp[i] = dp[i+1]; for(int i=1; i<=N*N+1; i++) mxm[i] = -INF; for(auto x : large) for(int i=N*N; i>=x; i--) mxm[i] = max(mxm[i], mxm[i-x] + 1); int res = INF; for(int i=0; i<=N*N; i++) if(mxm[i] >= 0) res = min(res, i + dp[max(tot - i, n*max(0, k - mxm[i]))]); if(res == INF) cout << "Impossible\n"; else cout << res - tot << "\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...