#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 300 + 11;
int a[MAXN], b[MAXN];
int dp[MAXN * MAXN]; // for fixed sum, maximise count
int32_t main(){
int n, m, k; cin >> n >> m >> k;
for(int i = 0; i < n; i++) cin >> a[i];
for(int j = 0; j < m; j++) cin >> b[j];
for(int i = 0; i < n; i++){
if(a[i] < k){
cout << "Impossible" << endl;
return 0;
}
}
int s_a = accumulate(a, a + n, 0LL);
int s_b = 0, c_b = 0;
for(int j = 0; j < m; j++) s_b += b[j], c_b += min(b[j], n);
if(s_a > s_b || n * k > c_b){
cout << "Impossible" << endl;
return 0;
}
fill(dp + 1, dp + MAXN * MAXN, -(1LL << 60));
for(int j = 0; j < m; j++){
for(int i = MAXN * MAXN - 1 - b[j]; i >= 0; i--){
dp[i + b[j]] = max(dp[i + b[j]], dp[i] + min(b[j], n));
}
}
for(int i = s_a;; i++){
if(dp[i] >= k * n){
cout << i - s_a << endl;
return 0;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
2 ms |
980 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1060 KB |
Output is correct |
2 |
Correct |
17 ms |
980 KB |
Output is correct |
3 |
Correct |
22 ms |
980 KB |
Output is correct |
4 |
Correct |
22 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
16 ms |
1060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
980 KB |
Output is correct |
2 |
Correct |
4 ms |
980 KB |
Output is correct |
3 |
Correct |
4 ms |
980 KB |
Output is correct |
4 |
Correct |
4 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
2 ms |
980 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
20 ms |
1060 KB |
Output is correct |
15 |
Correct |
17 ms |
980 KB |
Output is correct |
16 |
Correct |
22 ms |
980 KB |
Output is correct |
17 |
Correct |
22 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
308 KB |
Output is correct |
19 |
Correct |
16 ms |
1060 KB |
Output is correct |
20 |
Correct |
4 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
980 KB |
Output is correct |
22 |
Correct |
4 ms |
980 KB |
Output is correct |
23 |
Correct |
4 ms |
980 KB |
Output is correct |
24 |
Correct |
1 ms |
308 KB |
Output is correct |
25 |
Correct |
16 ms |
1068 KB |
Output is correct |
26 |
Correct |
18 ms |
980 KB |
Output is correct |
27 |
Correct |
12 ms |
956 KB |
Output is correct |
28 |
Correct |
18 ms |
1064 KB |
Output is correct |
29 |
Correct |
18 ms |
980 KB |
Output is correct |
30 |
Correct |
22 ms |
980 KB |
Output is correct |