#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991
const int maxn = 301;
int n, m, k, cntAK, cntBN, smA, smB, ans = 1e9;
int A[maxn], B[maxn];
int dp[maxn][maxn*maxn];
int rec (int i, int sm) {
if (sm == 0) return 0;
if (i == m || sm < 0) return -INT_MAX;
if (dp[i][sm] != -1) return dp[i][sm];
return dp[i][sm] = max(rec(i + 1, sm), rec(i + 1, sm - B[i]) + min(B[i], n));
}
signed main () {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 0 ; i < n ; i++) {
cin >> A[i];
smA += A[i];
if (A[i] < k) cntAK++;
}
for (int i = 0 ; i < m ; i++) {
cin >> B[i];
cntBN += min(n, B[i]);
smB += B[i];
}
if (m < k || smB < smA || cntBN/n < k || cntAK) {
// assert(0);
cout << "Impossible\n";
return 0;
}
memset(dp, -1, sizeof dp);
for (int i = smA ; i < maxn * maxn ; i++) {
if (rec(0, i) / n >= k) {
ans = min(ans, i - smA);
break;
}
}
cout << ans << endl;
}
/*
impossible:
- M < K
- sum of B < sum of A
- the number of (B >= N) is < K
- theres an A which is < K
*/
Compilation message
kitchen.cpp:17:1: warning: multi-line comment [-Wcomment]
17 | //\
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
213752 KB |
Output is correct |
2 |
Correct |
104 ms |
213708 KB |
Output is correct |
3 |
Correct |
81 ms |
213740 KB |
Output is correct |
4 |
Correct |
83 ms |
213708 KB |
Output is correct |
5 |
Correct |
82 ms |
213736 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
288 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
213752 KB |
Output is correct |
2 |
Correct |
104 ms |
213708 KB |
Output is correct |
3 |
Correct |
81 ms |
213740 KB |
Output is correct |
4 |
Correct |
83 ms |
213708 KB |
Output is correct |
5 |
Correct |
82 ms |
213736 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
288 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
83 ms |
213764 KB |
Output is correct |
10 |
Correct |
85 ms |
213756 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
89 ms |
213712 KB |
Output is correct |
13 |
Correct |
83 ms |
213680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
213668 KB |
Output is correct |
2 |
Correct |
119 ms |
213784 KB |
Output is correct |
3 |
Correct |
153 ms |
213688 KB |
Output is correct |
4 |
Correct |
229 ms |
213708 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
122 ms |
213872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
213728 KB |
Output is correct |
2 |
Correct |
81 ms |
213720 KB |
Output is correct |
3 |
Correct |
84 ms |
213684 KB |
Output is correct |
4 |
Correct |
83 ms |
213768 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
213752 KB |
Output is correct |
2 |
Correct |
104 ms |
213708 KB |
Output is correct |
3 |
Correct |
81 ms |
213740 KB |
Output is correct |
4 |
Correct |
83 ms |
213708 KB |
Output is correct |
5 |
Correct |
82 ms |
213736 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
288 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
83 ms |
213764 KB |
Output is correct |
10 |
Correct |
85 ms |
213756 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
89 ms |
213712 KB |
Output is correct |
13 |
Correct |
83 ms |
213680 KB |
Output is correct |
14 |
Correct |
127 ms |
213668 KB |
Output is correct |
15 |
Correct |
119 ms |
213784 KB |
Output is correct |
16 |
Correct |
153 ms |
213688 KB |
Output is correct |
17 |
Correct |
229 ms |
213708 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
122 ms |
213872 KB |
Output is correct |
20 |
Correct |
85 ms |
213728 KB |
Output is correct |
21 |
Correct |
81 ms |
213720 KB |
Output is correct |
22 |
Correct |
84 ms |
213684 KB |
Output is correct |
23 |
Correct |
83 ms |
213768 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
178 ms |
213780 KB |
Output is correct |
26 |
Correct |
294 ms |
213776 KB |
Output is correct |
27 |
Correct |
108 ms |
213712 KB |
Output is correct |
28 |
Correct |
155 ms |
213784 KB |
Output is correct |
29 |
Correct |
191 ms |
213892 KB |
Output is correct |
30 |
Correct |
231 ms |
213900 KB |
Output is correct |