#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 300 + 5;
int dp[MAXN * MAXN];
#define ONLINE_JUDGE
void solve() {
fill_n(&dp[0], MAXN * MAXN, int(-1E4));
int n, m, k;
cin >> n >> m >> k;
vector <int> a(n);
for(int &i : a)
cin >> i;
vector <int> b(m);
for(int &i : b)
cin >> i;
bool check = true;
for(int &i : a)
check &= (k <= i);
if(!check) {
return cout << "Impossible", void();
}
dp[0] = 0;
for(int i = 0; i < m; i++) {
for(int j = MAXN * MAXN -1; j >= b[i]; j--) {
dp[j] = max(dp[j], dp[j - b[i]] +1);
}
}
int cev = MAXN * MAXN +1, suma = accumulate(a.begin(), a.end(), 0);
for(int i = MAXN * MAXN -1; i >= suma; i--) {
if(dp[i] >= k) {
cev = i;
}
}
if(cev == MAXN * MAXN +1)
cout << "Impossible";
else
cout << cev - suma;
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
824 KB |
Output is correct |
7 |
Correct |
1 ms |
824 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
824 KB |
Output is correct |
7 |
Correct |
1 ms |
824 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
604 KB |
Output is correct |
2 |
Correct |
20 ms |
604 KB |
Output is correct |
3 |
Correct |
27 ms |
600 KB |
Output is correct |
4 |
Correct |
33 ms |
604 KB |
Output is correct |
5 |
Correct |
26 ms |
604 KB |
Output is correct |
6 |
Correct |
19 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
824 KB |
Output is correct |
7 |
Correct |
1 ms |
824 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |