#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vii vector<pair<int, int>>
#define vi vector<int>
#define vl vector<long long>
#define vll vector<pair<long long, long long>>
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i = a;i<=b;i++)
#define f first
#define s second
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
#define start int tt;cin>>tt;rep(testcase, 1, tt)
#define print(k) cout<<"Case #"<<testcase<<": "<<k<<"\n";
#define endl "\n"
#define DEBUG(k) cerr<<k<<"\n";
void solve() {
int n, m, k, sum = 0;
cin >> n >> m >> k;
int b[m], need = 0, tmp;
rep(i, 0, n-1){
cin>>tmp;need+=tmp;
}
rep(i, 0, m-1){
cin>>b[i];
sum+=b[i];
}
vector<bool> dp(sum+1, 0);
dp[0] = 1;
for(int k:b) {
for(int i = sum;i>=k;i--) {
if(dp[i-k] == 1)dp[i] = 1;
}
}
int index = -1;
for(int i = need;i<=sum;i++) {
if(dp[i] == 1){
index = i;
break;
}
}
if(index == -1)cout<<"Impossible"<<endl;
else cout<<index - need<<endl;
}
int main () {/*
#ifndef ONLINE_JUDGE
freopen("stdin", "r", stdin);
freopen("stdout", "w", stdout);
freopen("stderr", "w", stderr);
#endif*/
int t = 1;
// cin >> t;
while(t--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
204 KB |
Output is correct |
2 |
Correct |
23 ms |
296 KB |
Output is correct |
3 |
Correct |
30 ms |
204 KB |
Output is correct |
4 |
Correct |
50 ms |
204 KB |
Output is correct |
5 |
Correct |
49 ms |
284 KB |
Output is correct |
6 |
Correct |
20 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |