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;
int n,m,k,dp[90005],a[305],b[305],sum;
void impossible(){
cout << "Impossible\n";
exit(0);
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> k;
if (m < k) impossible();
for (int i=1;i<=n;i++){
cin >> a[i];
sum+=a[i];
if (a[i] < k) impossible();
}
for (int i=1;i<=90000;i++){
dp[i]=-1;
}
for (int i=1;i<=m;i++){
cin >> b[i];
for (int j=90000;j>=b[i];j--){
if (dp[j] == -1 && dp[j-b[i]] >= 0)
dp[j]=dp[j-b[i]]+min(b[i],n);
else
if (dp[j] > 0 && dp[j-b[i]] >= 0)
dp[j]=max(dp[j],dp[j-b[i]]+min(b[i],n));
}
}
for (int i=sum;i<=90000;i++){
if (dp[i] >= n*k){
cout << i-sum << "\n";
return 0;
}
}
impossible();
return 0;
}
# | 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... |