#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template <class T, class... U> void bug_h(const T& t, const U&... u) { cerr << t; ((cerr << " | " << u), ...); cerr << endl; }
#define bug(...) cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; bug_h(__VA_ARGS__)
#else
#define cerr if (false) cerr
#define bug(...)
#endif
#define ar array
#define all(v) std::begin(v), std::end(v)
#define sz(v) int(std::size(v))
typedef long long i64;
typedef vector<int> vi;
typedef pair<int, int> pi;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int N, M, K;
cin >> N >> M >> K;
vi A(N), B(M);
for (auto &x : A) cin >> x;
for (auto &x : B) cin >> x;
if (*min_element(all(A)) < K) {
cout << "Impossible\n";
return 0;
}
int sum_a = accumulate(all(A), 0);
const int MAXB = 300;
vi dp(MAXB * M + 1, -N * M);
dp[0] = 0;
for (int i = 0; i < M; i++) {
int weight = B[i], value = min(B[i], N);
for (int j = MAXB * M; j >= weight; j--) dp[j] = max(dp[j], dp[j - weight] + value);
}
for (int j = sum_a; j <= MAXB * M; j++) if (dp[j] >= N * K) {
cout << j - sum_a << '\n';
return 0;
}
cout << "Impossible\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
600 KB |
Output is correct |
2 |
Correct |
14 ms |
640 KB |
Output is correct |
3 |
Correct |
20 ms |
600 KB |
Output is correct |
4 |
Correct |
23 ms |
604 KB |
Output is correct |
5 |
Correct |
19 ms |
604 KB |
Output is correct |
6 |
Correct |
10 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
452 KB |
Output is correct |
14 |
Correct |
15 ms |
600 KB |
Output is correct |
15 |
Correct |
14 ms |
640 KB |
Output is correct |
16 |
Correct |
20 ms |
600 KB |
Output is correct |
17 |
Correct |
23 ms |
604 KB |
Output is correct |
18 |
Correct |
19 ms |
604 KB |
Output is correct |
19 |
Correct |
10 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
456 KB |
Output is correct |
25 |
Correct |
10 ms |
604 KB |
Output is correct |
26 |
Correct |
16 ms |
604 KB |
Output is correct |
27 |
Correct |
8 ms |
604 KB |
Output is correct |
28 |
Correct |
16 ms |
604 KB |
Output is correct |
29 |
Correct |
14 ms |
604 KB |
Output is correct |
30 |
Correct |
20 ms |
604 KB |
Output is correct |