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;
const int N=350,M=100050;
int n,m,k,a[N],b[N],dp[N][M],sum;
int main(){
cin>>n>>m>>k;
for (int i=1;i<=n;i++) {
cin>>a[i];
if (a[i]<k){
cout<<"Impossible\n";
return 0;
}
sum+=a[i];
}
for (int i=1;i<=m;i++) cin>>b[i];
for (int i=0;i<=m;i++) for (int j=0;j<M;j++) dp[i][j]=INT_MIN;
dp[0][0]=0;
for (int i=1;i<=m;i++) for (int j=0;j<M;j++){
if (j<b[i]) dp[i][j]=dp[i-1][j];
else if (b[i]>n) dp[i][j]=max(dp[i-1][j],dp[i-1][j-b[i]]+n);
else dp[i][j]=max(dp[i-1][j],dp[i-1][j-b[i]]+b[i]);
}
for (int j=sum;j<M;j++){
if (dp[m][j]>=n*k){
cout<<j-sum<<"\n";
return 0;
}
}
cout<<"Impossible\n";
}
# | 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... |