#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
#define no cout<<"Impossible"<<endl;return 0;
const int N=200005;
const int INF=1e18;
int32_t main() {
LCBorz;
int n,m,k;cin>>n>>m>>k;
if(m<k){
no;
}
vector<int> a(n),b(m);
int total=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]<k){
no;
}
total+=a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
vector<int> dp(N);
dp[0]=1;
for(int i=0;i<m;i++){
for(int j=N-1;j>=b[i];j--){
dp[j]|=dp[j-b[i]];
}
}
int ans=-1;
for(int i=total;i<N;i++){
if(dp[i]){
ans=i;break;
}
}
if(ans==-1){
no;
}
else{
cout<<ans-total<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Incorrect |
2 ms |
1988 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Incorrect |
2 ms |
1988 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
1884 KB |
Output is correct |
2 |
Correct |
35 ms |
1880 KB |
Output is correct |
3 |
Correct |
56 ms |
1988 KB |
Output is correct |
4 |
Correct |
40 ms |
1884 KB |
Output is correct |
5 |
Correct |
46 ms |
1880 KB |
Output is correct |
6 |
Correct |
32 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Incorrect |
2 ms |
1988 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |