#include <bits/stdc++.h>
using namespace std;
const int maxn=310;
int v[maxn], dp[maxn][maxn*maxn], pd[maxn][maxn*maxn];
int main()
{
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n, m, k; cin >> n >> m >> k;
int sum=0;
for(int i=1;i<=n;i++){
int a; cin >> a;
sum+=a;
if(a<k){
cout << "Impossible" << endl;
return 0;
}
}
pd[0][0]=1;
for(int i=1;i<=m;i++) cin >> v[i];
for(int i=1;i<=m;i++){
for(int j=0;j<v[i];j++){
dp[i][j]=dp[i-1][j];
pd[i][j]=pd[i-1][j];
}
for(int j=0;j<maxn*maxn-v[i];j++){
if(pd[i-1][j]){
dp[i][j+v[i]]=max(dp[i-1][j+v[i]],dp[i-1][j]+min(v[i],n));
pd[i][j+v[i]]=1;
}else dp[i][j+v[i]]=dp[i-1][j+v[i]];
pd[i][j+v[i]]=max(pd[i-1][j+v[i]],pd[i][j]);
}
}
for(int i=sum;i<maxn*maxn;i++){
if((dp[m][i]/n)>=k){
cout << i-sum << endl;
return 0;
}
}
cout << "Impossible" << endl;
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... |