#include <bits/stdc++.h>
using namespace std;
int n, m, k, dp[(300 * 303)], a[300], b[300], sum = 0;
int gt[(300*303)];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
int mn = 1e9;
for (int i = 0; i < n; i++) {
cin >> a[i];
gt[a[i]]++;
sum += a[i];
mn = min(mn, a[i]);
}
if (mn < k) {
cout << "Impossible";
return 0;
}
for (int i = 300*301; i >= 0; i--) {
gt[i] += gt[i+1];
}
for (int i = 1; i <= 300*301; i++) {
dp[i] = -1e9;
}
for (int i = 0; i < m; i++) {
cin >> b[i];
for (int j = 300*301; j >= b[i]; j--) {
dp[j] = max(dp[j], min(b[i], n) + dp[j-b[i]]);
}
}
for (int i = sum; i <= 300 * 301 ; i++) {
if (dp[i] >= n * k) {
cout << i - sum;
return 0;
}
}
cout << "Impossible";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
1116 KB |
Output is correct |
2 |
Correct |
13 ms |
1172 KB |
Output is correct |
3 |
Correct |
17 ms |
1116 KB |
Output is correct |
4 |
Correct |
17 ms |
1116 KB |
Output is correct |
5 |
Correct |
16 ms |
1116 KB |
Output is correct |
6 |
Correct |
12 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1116 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
3 |
Correct |
3 ms |
1116 KB |
Output is correct |
4 |
Correct |
3 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
15 ms |
1116 KB |
Output is correct |
15 |
Correct |
13 ms |
1172 KB |
Output is correct |
16 |
Correct |
17 ms |
1116 KB |
Output is correct |
17 |
Correct |
17 ms |
1116 KB |
Output is correct |
18 |
Correct |
16 ms |
1116 KB |
Output is correct |
19 |
Correct |
12 ms |
1116 KB |
Output is correct |
20 |
Correct |
4 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
1116 KB |
Output is correct |
22 |
Correct |
3 ms |
1116 KB |
Output is correct |
23 |
Correct |
3 ms |
1116 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
12 ms |
1116 KB |
Output is correct |
26 |
Correct |
14 ms |
1116 KB |
Output is correct |
27 |
Correct |
9 ms |
1116 KB |
Output is correct |
28 |
Correct |
14 ms |
1168 KB |
Output is correct |
29 |
Correct |
14 ms |
1116 KB |
Output is correct |
30 |
Correct |
17 ms |
1176 KB |
Output is correct |