#include<bits/stdc++.h>
using namespace std;
const int maxn=300+10;
int dp[maxn*maxn],fake[maxn*maxn],inf=1e9+5;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for(int i=0;i<maxn*maxn;i++){
dp[i]=-inf;
}
int n,m,k;
cin>>n>>m>>k;
vector<int>alln(n),allm(m);
int f=0;
int sumn=0;
for(int i=0;i<n;i++){
cin>>alln[i];
if(alln[i]<k){
f=1;
}
sumn+=alln[i];
}
int summ=0,mainsumm=0;
for(int i=0;i<m;i++){
cin>>allm[i];
summ+=min(allm[i],n);
mainsumm+=allm[i];
}
if(f==1||summ<n*k||mainsumm<sumn){
cout<<"Impossible\n";
return 0;
}
int res=inf;
dp[0]=0;
for(int i=0;i<m;i++){
for(int j=0;j<maxn*maxn;j++){
fake[j]=dp[j];
dp[j]=-inf;
}
for(int j=0;j<maxn*maxn;j++){
if(j<allm[i]){
dp[j]=fake[j];
continue;
}
dp[j]=max(fake[j],fake[j-allm[i]]+min(n,allm[i]));
}
}
//cout<<dp[4]<<" "<<dp[7]<<" "<<dp[3]<<"\n";
for(int i=0;i<maxn*maxn;i++){
if(i>=sumn&&dp[i]>=n*k){
res=min(res,i-sumn);
}
}
cout<<res<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
2 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
2 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
980 KB |
Output is correct |
10 |
Correct |
4 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
980 KB |
Output is correct |
13 |
Correct |
4 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
1064 KB |
Output is correct |
2 |
Correct |
44 ms |
980 KB |
Output is correct |
3 |
Correct |
60 ms |
1064 KB |
Output is correct |
4 |
Correct |
58 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
700 KB |
Output is correct |
6 |
Correct |
42 ms |
960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
952 KB |
Output is correct |
2 |
Correct |
9 ms |
1068 KB |
Output is correct |
3 |
Correct |
9 ms |
1068 KB |
Output is correct |
4 |
Correct |
10 ms |
980 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
2 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
980 KB |
Output is correct |
10 |
Correct |
4 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
980 KB |
Output is correct |
13 |
Correct |
4 ms |
980 KB |
Output is correct |
14 |
Correct |
53 ms |
1064 KB |
Output is correct |
15 |
Correct |
44 ms |
980 KB |
Output is correct |
16 |
Correct |
60 ms |
1064 KB |
Output is correct |
17 |
Correct |
58 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
700 KB |
Output is correct |
19 |
Correct |
42 ms |
960 KB |
Output is correct |
20 |
Correct |
9 ms |
952 KB |
Output is correct |
21 |
Correct |
9 ms |
1068 KB |
Output is correct |
22 |
Correct |
9 ms |
1068 KB |
Output is correct |
23 |
Correct |
10 ms |
980 KB |
Output is correct |
24 |
Correct |
0 ms |
596 KB |
Output is correct |
25 |
Correct |
41 ms |
1052 KB |
Output is correct |
26 |
Correct |
56 ms |
992 KB |
Output is correct |
27 |
Correct |
33 ms |
1056 KB |
Output is correct |
28 |
Correct |
46 ms |
980 KB |
Output is correct |
29 |
Correct |
51 ms |
1056 KB |
Output is correct |
30 |
Correct |
56 ms |
1100 KB |
Output is correct |