#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 300 + 5;
const int inf = 1e9;
const int mod = 1e9 + 7;
int a[N], b[N], dp[N * N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
int moze = 1;
int sa, sb;
sa = sb = 0;
for (int i = 1; i <= n; i++) {
sa += a[i];
if (a[i] < k) moze = 0;
}
for (int i = 1; i <= m; i++) sb += b[i];
if (moze == 0) {
cout << "Impossible" << en;
return 0;
}
for (int i = 1; i < N * N; i++) dp[i] = -inf;
for (int i = 1; i <= m; i++) {
for (int j = N * N - 1; j >= b[i]; j--) smax(dp[j], dp[j - b[i]] + min(b[i], n));
}
for (int i = sa; i < N * N; i++) {
if (dp[i] >= n * k) {
cout << i - sa << en;
return 0;
}
}
cout << "Impossible" << en;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
692 KB |
Output is correct |
2 |
Correct |
17 ms |
696 KB |
Output is correct |
3 |
Correct |
23 ms |
596 KB |
Output is correct |
4 |
Correct |
23 ms |
676 KB |
Output is correct |
5 |
Correct |
24 ms |
696 KB |
Output is correct |
6 |
Correct |
16 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
596 KB |
Output is correct |
2 |
Correct |
4 ms |
596 KB |
Output is correct |
3 |
Correct |
4 ms |
596 KB |
Output is correct |
4 |
Correct |
4 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
20 ms |
692 KB |
Output is correct |
15 |
Correct |
17 ms |
696 KB |
Output is correct |
16 |
Correct |
23 ms |
596 KB |
Output is correct |
17 |
Correct |
23 ms |
676 KB |
Output is correct |
18 |
Correct |
24 ms |
696 KB |
Output is correct |
19 |
Correct |
16 ms |
596 KB |
Output is correct |
20 |
Correct |
4 ms |
596 KB |
Output is correct |
21 |
Correct |
4 ms |
596 KB |
Output is correct |
22 |
Correct |
4 ms |
596 KB |
Output is correct |
23 |
Correct |
4 ms |
596 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
16 ms |
596 KB |
Output is correct |
26 |
Correct |
19 ms |
596 KB |
Output is correct |
27 |
Correct |
16 ms |
596 KB |
Output is correct |
28 |
Correct |
20 ms |
676 KB |
Output is correct |
29 |
Correct |
20 ms |
596 KB |
Output is correct |
30 |
Correct |
24 ms |
596 KB |
Output is correct |