/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 300;
const int M_MAX = 300;
const int T_MAX = 300;
const int INF = INT_MAX / 2;
int N, M, K;
int A[N_MAX + 2];
int B[M_MAX + 2];
int sumA, sumB;
int dp[M_MAX * T_MAX + 2];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M >> K;
for (int i = 1; i <= N; i++) {
cin >> A[i];
sumA += A[i];
}
for (int i = 1; i <= M; i++) {
cin >> B[i];
sumB += B[i];
}
for (int i = 1; i <= N; i++) {
if (A[i] < K) {
cout << "Impossible\n";
return 0;
}
}
fill(dp + 1, dp + sumB + 1, -INF);
for (int i = 1; i <= M; i++) {
for (int t = sumB; t >= B[i]; t--) {
dp[t] = max(dp[t], dp[t - B[i]] + min(B[i], N));
}
}
int sum = sumA;
while (sum <= sumB && dp[sum] < N * K) {
sum++;
}
if (sum > sumB) {
cout << "Impossible\n";
} else {
cout << sum - sumA << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
592 KB |
Output is correct |
2 |
Correct |
11 ms |
556 KB |
Output is correct |
3 |
Correct |
12 ms |
520 KB |
Output is correct |
4 |
Correct |
20 ms |
596 KB |
Output is correct |
5 |
Correct |
20 ms |
664 KB |
Output is correct |
6 |
Correct |
10 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
15 ms |
592 KB |
Output is correct |
15 |
Correct |
11 ms |
556 KB |
Output is correct |
16 |
Correct |
12 ms |
520 KB |
Output is correct |
17 |
Correct |
20 ms |
596 KB |
Output is correct |
18 |
Correct |
20 ms |
664 KB |
Output is correct |
19 |
Correct |
10 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
10 ms |
468 KB |
Output is correct |
26 |
Correct |
13 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
332 KB |
Output is correct |
28 |
Correct |
12 ms |
536 KB |
Output is correct |
29 |
Correct |
14 ms |
600 KB |
Output is correct |
30 |
Correct |
21 ms |
596 KB |
Output is correct |