#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
const int N = 3e2 + 5;
int a[N], b[N], dp[N * N];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, m, k, sum1 = 0, sum2 = 0;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] < k) {
cout << "Impossible\n";
return 0;
}
sum1 += a[i];
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
sum2 += b[i];
}
for (int i = 1; i <= sum2; i++) dp[i] = -1e9;
for (int i = 1; i <= m; i++) {
for (int j = sum2; j >= b[i]; j--) dp[j] = max(dp[j], dp[j - b[i]] + min(b[i], n));
}
for (int i = sum1; i <= sum2; i++) {
if (dp[i] >= n * k) {
cout << i - sum1 << "\n";
return 0;
}
}
cout << "Impossible\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
592 KB |
Output is correct |
2 |
Correct |
10 ms |
556 KB |
Output is correct |
3 |
Correct |
12 ms |
468 KB |
Output is correct |
4 |
Correct |
18 ms |
652 KB |
Output is correct |
5 |
Correct |
18 ms |
664 KB |
Output is correct |
6 |
Correct |
8 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
13 ms |
592 KB |
Output is correct |
15 |
Correct |
10 ms |
556 KB |
Output is correct |
16 |
Correct |
12 ms |
468 KB |
Output is correct |
17 |
Correct |
18 ms |
652 KB |
Output is correct |
18 |
Correct |
18 ms |
664 KB |
Output is correct |
19 |
Correct |
8 ms |
528 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
10 ms |
468 KB |
Output is correct |
26 |
Correct |
14 ms |
468 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
10 ms |
536 KB |
Output is correct |
29 |
Correct |
14 ms |
604 KB |
Output is correct |
30 |
Correct |
19 ms |
648 KB |
Output is correct |