#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;
const int maxN = 305;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n), b(m);
for(int& i : a) {
cin >> i;
}
for(int& i : b) {
cin >> i;
}
int ans = INF;
for(int i : a) {
if (i < k) {
cout << "Impossible\n";
exit(0);
}
}
int dp[m+2][maxN*maxN];
int time = accumulate(a.begin(), a.end(), 0);
for(int i = 0; i <= m; i++) {
for(int j = 0; j < maxN*maxN; j++) {
dp[i][j] = -INF;
}
}
dp[0][0] = 0;
for(int i = 1; i <= m; i++) {
for(int j = 0; j < maxN*maxN; j++) {
dp[i][j] = dp[i-1][j];
if (j-b[i-1] < 0) continue;
dp[i][j] = max(dp[i][j], dp[i-1][j-b[i-1]] + min(n, b[i-1]));
if (dp[i][j] >= k*n && j >= time && j-time < ans) {
ans = j-time;
}
}
}
if (ans == INF) {
cout << "Impossible\n";
} else {
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1740 KB |
Output is correct |
2 |
Correct |
1 ms |
1740 KB |
Output is correct |
3 |
Correct |
2 ms |
1740 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
2 ms |
1740 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
1740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1740 KB |
Output is correct |
2 |
Correct |
1 ms |
1740 KB |
Output is correct |
3 |
Correct |
2 ms |
1740 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
2 ms |
1740 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
1740 KB |
Output is correct |
9 |
Correct |
7 ms |
6476 KB |
Output is correct |
10 |
Correct |
7 ms |
6476 KB |
Output is correct |
11 |
Correct |
7 ms |
6476 KB |
Output is correct |
12 |
Correct |
7 ms |
6476 KB |
Output is correct |
13 |
Correct |
7 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
96172 KB |
Output is correct |
2 |
Correct |
92 ms |
83256 KB |
Output is correct |
3 |
Correct |
121 ms |
110228 KB |
Output is correct |
4 |
Correct |
120 ms |
110148 KB |
Output is correct |
5 |
Correct |
116 ms |
106608 KB |
Output is correct |
6 |
Correct |
84 ms |
76868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
15584 KB |
Output is correct |
2 |
Correct |
18 ms |
15588 KB |
Output is correct |
3 |
Correct |
17 ms |
15600 KB |
Output is correct |
4 |
Correct |
17 ms |
15592 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1740 KB |
Output is correct |
2 |
Correct |
1 ms |
1740 KB |
Output is correct |
3 |
Correct |
2 ms |
1740 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
2 ms |
1740 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
1740 KB |
Output is correct |
9 |
Correct |
7 ms |
6476 KB |
Output is correct |
10 |
Correct |
7 ms |
6476 KB |
Output is correct |
11 |
Correct |
7 ms |
6476 KB |
Output is correct |
12 |
Correct |
7 ms |
6476 KB |
Output is correct |
13 |
Correct |
7 ms |
6488 KB |
Output is correct |
14 |
Correct |
106 ms |
96172 KB |
Output is correct |
15 |
Correct |
92 ms |
83256 KB |
Output is correct |
16 |
Correct |
121 ms |
110228 KB |
Output is correct |
17 |
Correct |
120 ms |
110148 KB |
Output is correct |
18 |
Correct |
116 ms |
106608 KB |
Output is correct |
19 |
Correct |
84 ms |
76868 KB |
Output is correct |
20 |
Correct |
17 ms |
15584 KB |
Output is correct |
21 |
Correct |
18 ms |
15588 KB |
Output is correct |
22 |
Correct |
17 ms |
15600 KB |
Output is correct |
23 |
Correct |
17 ms |
15592 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
84 ms |
77464 KB |
Output is correct |
26 |
Correct |
98 ms |
89524 KB |
Output is correct |
27 |
Correct |
66 ms |
59204 KB |
Output is correct |
28 |
Correct |
97 ms |
89792 KB |
Output is correct |
29 |
Correct |
100 ms |
91972 KB |
Output is correct |
30 |
Correct |
118 ms |
110148 KB |
Output is correct |