# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1005501 | anango | Kitchen (BOI19_kitchen) | C++17 | 213 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |