#include <iostream>
#include <vector>
using namespace std;
int const MAX_N = 300;
int const MAX_M = 300;
int const MAX_WORK = MAX_N * (MAX_M + 1);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
vector<int> dp(MAX_WORK + 1, -1);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
int total_work = 0;
for (int& x : a) {
cin >> x;
total_work += x;
if (x < k) {
cout << "Impossible\n";
return 0;
}
}
int const difference_work = n * k;
if (total_work > MAX_WORK || difference_work > MAX_WORK) {
cout << "Impossible\n";
return 0;
}
vector<int> b(m);
for (int& x : b)
cin >> x;
dp[0] = 0;
for (int const& chef : b) {
int const delta_d = min(chef, n);
int const delta_t = chef;
for (int t = MAX_WORK; t >= delta_t; t--) {
if (dp[t - delta_t] == -1)
continue;
int const new_d = dp[t - delta_t] + delta_d;
dp[t] = max(dp[t], new_d);
}
}
for (int t = total_work; t <= MAX_WORK; t++) {
if (dp[t] >= difference_work) {
cout << t - total_work << "\n";
return 0;
}
}
cout << "Impossible\n";
}
# |
결과 |
실행 시간 |
메모리 |
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 |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
596 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 |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
596 KB |
Output is correct |
2 |
Correct |
20 ms |
596 KB |
Output is correct |
3 |
Correct |
26 ms |
596 KB |
Output is correct |
4 |
Correct |
22 ms |
596 KB |
Output is correct |
5 |
Correct |
20 ms |
596 KB |
Output is correct |
6 |
Correct |
15 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
4 |
Correct |
5 ms |
596 KB |
Output is correct |
5 |
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 |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
26 ms |
596 KB |
Output is correct |
15 |
Correct |
20 ms |
596 KB |
Output is correct |
16 |
Correct |
26 ms |
596 KB |
Output is correct |
17 |
Correct |
22 ms |
596 KB |
Output is correct |
18 |
Correct |
20 ms |
596 KB |
Output is correct |
19 |
Correct |
15 ms |
596 KB |
Output is correct |
20 |
Correct |
3 ms |
596 KB |
Output is correct |
21 |
Correct |
3 ms |
596 KB |
Output is correct |
22 |
Correct |
3 ms |
596 KB |
Output is correct |
23 |
Correct |
5 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
15 ms |
596 KB |
Output is correct |
26 |
Correct |
20 ms |
596 KB |
Output is correct |
27 |
Correct |
12 ms |
596 KB |
Output is correct |
28 |
Correct |
19 ms |
596 KB |
Output is correct |
29 |
Correct |
18 ms |
596 KB |
Output is correct |
30 |
Correct |
22 ms |
596 KB |
Output is correct |