#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m, k;
std::cin >> n >> m >> k;
std::vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < m; i++) {
std::cin >> b[i];
}
int64_t suma = 0;
int64_t sumb = 0;
for (int i = 0; i < n; i++) {
suma += a[i];
}
for (int i = 0; i < m; i++) {
sumb += b[i];
}
if (m < k || sumb < suma) {
std::cout << "Impossible\n";
return 0;
}
for (int i = 0; i < n; i++) {
if (a[i] < k) {
std::cout << "Impossible\n";
return 0;
}
}
std::vector<std::vector<int>> dp(m + 1, std::vector<int>(sumb + 1));
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= sumb; j++) {
dp[i][j] = -1;
}
}
dp[0][0] = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j <= sumb; j++) {
if (dp[i][j] == -1) {
continue;
}
dp[i + 1][j] = dp[i][j];
if (j + b[i] <= sumb) {
dp[i + 1][j + b[i]] = std::max(dp[i + 1][j + b[i]], dp[i][j] + std::min(b[i], n));
}
}
}
for (int j = suma; j <= sumb; j++) {
if (dp[m][j] >= n * k) {
std::cout << j - suma << "\n";
return 0;
}
}
std::cout << "Impossible\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Incorrect |
1 ms |
592 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
68948 KB |
Output is correct |
2 |
Correct |
50 ms |
51552 KB |
Output is correct |
3 |
Correct |
62 ms |
57164 KB |
Output is correct |
4 |
Correct |
117 ms |
98424 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
44 ms |
41552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Incorrect |
1 ms |
592 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |