#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
const ll M=90000+10;
const ll inf=1e18+10;
ll n,m,k,sum,b[M];
bitset<4510>dp[2][4510];
bitset<100001>dpp;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n>>m>>k;
if(k>1){
for(int i=0;i<n;i++){
ll x;
cin>>x;
if(x<k){
cout<<"Impossible";
return 0;
}
sum+=x;
}
ll sb=0,sb1=0;
for(int i=0;i<m;i++)
cin>>b[i],sb+=b[i],sb1+=min(n,b[i]);
sb++;
sb1++;
dp[0][0][0]=1;
for(int i=0;i<m;i++){
for(int j=0;j<sb;j++){
for(int ii=0;ii<=n*k;ii++){
if(dp[0][j][ii]){
dp[1][j+b[i]][min(n*k,ii+min(b[i],n))]=1;
}
}
}
for(int j=0;j<sb;j++){
for(int ii=0;ii<=n*k;ii++){
if(dp[1][j][ii])
dp[0][j][ii]=1,dp[1][j][ii]=0;
}
}
}
for(ll i=sum;i<sb;i++){
if(dp[0][i][n*k]){
cout<<i-sum;
return 0;
}
}
cout<<"Impossible";
}
else{
for(int i=0;i<n;i++){
ll x;
cin>>x;
sum+=x;
}
for(int i=0;i<m;i++)
cin>>b[i];
dpp[0]=1;
for(int i=0;i<m;i++){
for(int j=90000;j>=0;j--){
if(dpp[j])
dpp[b[i]+j]=1;
}
}
for(int i=sum;i<90001;i++){
if(dpp[i]){
cout<<i-sum;
return 0;
}
}
cout<<"Impossible\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
3932 KB |
Output is correct |
10 |
Correct |
3 ms |
2904 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
4 ms |
2392 KB |
Output is correct |
13 |
Correct |
180 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
464 KB |
Output is correct |
2 |
Correct |
16 ms |
348 KB |
Output is correct |
3 |
Correct |
29 ms |
472 KB |
Output is correct |
4 |
Correct |
32 ms |
344 KB |
Output is correct |
5 |
Correct |
29 ms |
348 KB |
Output is correct |
6 |
Correct |
18 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
3152 KB |
Output is correct |
2 |
Correct |
38 ms |
2892 KB |
Output is correct |
3 |
Correct |
50 ms |
3052 KB |
Output is correct |
4 |
Correct |
127 ms |
3156 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
3932 KB |
Output is correct |
10 |
Correct |
3 ms |
2904 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
4 ms |
2392 KB |
Output is correct |
13 |
Correct |
180 ms |
4180 KB |
Output is correct |
14 |
Correct |
20 ms |
464 KB |
Output is correct |
15 |
Correct |
16 ms |
348 KB |
Output is correct |
16 |
Correct |
29 ms |
472 KB |
Output is correct |
17 |
Correct |
32 ms |
344 KB |
Output is correct |
18 |
Correct |
29 ms |
348 KB |
Output is correct |
19 |
Correct |
18 ms |
604 KB |
Output is correct |
20 |
Correct |
62 ms |
3152 KB |
Output is correct |
21 |
Correct |
38 ms |
2892 KB |
Output is correct |
22 |
Correct |
50 ms |
3052 KB |
Output is correct |
23 |
Correct |
127 ms |
3156 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Runtime error |
249 ms |
4552 KB |
Execution killed with signal 11 |
26 |
Halted |
0 ms |
0 KB |
- |