#include <bits/stdc++.h>
template <class T>
using Vec = std::vector<T>;
constexpr int INF = std::numeric_limits<int>::max() / 2;
constexpr int MAX = 300 * 300;
int main() {
int N, M, K;
std::cin >> N >> M >> K;
Vec<int> A(N);
for (auto& x: A) {
std::cin >> x;
if (x < K) {
std::cout << "Impossible\n";
return 0;
}
}
Vec<int> big, small;
for (int i = 0; i < M; ++i) {
int x;
std::cin >> x;
(x > N ? big : small).push_back(x);
}
std::array<int, MAX + 1> max;
max.fill(-1);
max[0] = 0;
for (const auto x: big) {
for (int i = MAX; i >= 0; --i) {
if (max[i] == -1) {
continue;
}
max[i + x] = std::max(max[i + x], max[i] + 1);
}
}
std::bitset<MAX + 1> gain;
gain.set(0);
for (const auto x: small) {
gain |= gain << x;
}
std::array<int, MAX + 1> lowb;
lowb.fill(INF);
for (int i = MAX; i >= 0; --i) {
if (gain.test(i)) {
lowb[i] = i;
}
if (i < MAX) {
lowb[i] = std::min(lowb[i], lowb[i + 1]);
}
}
const int whole = std::accumulate(A.begin(), A.end(), 0);
int ans = INF;
for (int i = 0; i <= MAX; ++i) {
if (max[i] == -1) {
continue;
}
const int rem1 = std::max(0, N * (K - max[i]));
const int rem2 = std::max(0, whole - i);
const int min = lowb[std::max(rem1, rem2)];
if (min != INF) {
ans = std::min(ans, min + i - whole);
}
}
if (ans == INF) {
std::cout << "Impossible\n";
}
else {
std::cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
972 KB |
Output is correct |
2 |
Correct |
2 ms |
940 KB |
Output is correct |
3 |
Correct |
2 ms |
972 KB |
Output is correct |
4 |
Correct |
2 ms |
972 KB |
Output is correct |
5 |
Correct |
2 ms |
940 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
2 ms |
944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
972 KB |
Output is correct |
2 |
Correct |
2 ms |
940 KB |
Output is correct |
3 |
Correct |
2 ms |
972 KB |
Output is correct |
4 |
Correct |
2 ms |
972 KB |
Output is correct |
5 |
Correct |
2 ms |
940 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
2 ms |
944 KB |
Output is correct |
9 |
Correct |
3 ms |
944 KB |
Output is correct |
10 |
Correct |
3 ms |
972 KB |
Output is correct |
11 |
Correct |
2 ms |
940 KB |
Output is correct |
12 |
Correct |
2 ms |
972 KB |
Output is correct |
13 |
Correct |
2 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
972 KB |
Output is correct |
2 |
Correct |
2 ms |
972 KB |
Output is correct |
3 |
Correct |
3 ms |
972 KB |
Output is correct |
4 |
Correct |
12 ms |
972 KB |
Output is correct |
5 |
Correct |
3 ms |
936 KB |
Output is correct |
6 |
Correct |
2 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
972 KB |
Output is correct |
2 |
Correct |
3 ms |
972 KB |
Output is correct |
3 |
Correct |
2 ms |
972 KB |
Output is correct |
4 |
Correct |
2 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
972 KB |
Output is correct |
2 |
Correct |
2 ms |
940 KB |
Output is correct |
3 |
Correct |
2 ms |
972 KB |
Output is correct |
4 |
Correct |
2 ms |
972 KB |
Output is correct |
5 |
Correct |
2 ms |
940 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
2 ms |
944 KB |
Output is correct |
9 |
Correct |
3 ms |
944 KB |
Output is correct |
10 |
Correct |
3 ms |
972 KB |
Output is correct |
11 |
Correct |
2 ms |
940 KB |
Output is correct |
12 |
Correct |
2 ms |
972 KB |
Output is correct |
13 |
Correct |
2 ms |
972 KB |
Output is correct |
14 |
Correct |
2 ms |
972 KB |
Output is correct |
15 |
Correct |
2 ms |
972 KB |
Output is correct |
16 |
Correct |
3 ms |
972 KB |
Output is correct |
17 |
Correct |
12 ms |
972 KB |
Output is correct |
18 |
Correct |
3 ms |
936 KB |
Output is correct |
19 |
Correct |
2 ms |
972 KB |
Output is correct |
20 |
Correct |
5 ms |
972 KB |
Output is correct |
21 |
Correct |
3 ms |
972 KB |
Output is correct |
22 |
Correct |
2 ms |
972 KB |
Output is correct |
23 |
Correct |
2 ms |
972 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
19 ms |
972 KB |
Output is correct |
26 |
Correct |
17 ms |
972 KB |
Output is correct |
27 |
Correct |
10 ms |
972 KB |
Output is correct |
28 |
Correct |
14 ms |
972 KB |
Output is correct |
29 |
Correct |
26 ms |
916 KB |
Output is correct |
30 |
Correct |
15 ms |
972 KB |
Output is correct |