#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
#define int long long
using namespace std;
const int sz = 3e2 + 6;
int a[sz], b[sz];
int dp[sz * sz];
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
int sm = 0;
bool f = false;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
sm += a[i];
if (a[i] < k) {
f = true;
}
}
for (int i = 1; i <= m; i ++) {
cin >> b[i];
}
if (f) {
goto ex;
}
for (int i = 1; i <= m; i ++) {
for (int j = sz * sz - 1; b[i] < j; j --) {
if (dp[j - b[i]]) {
dp[j] = max(dp[j], dp[j - b[i]] + min(b[i], n));
}
}
dp[b[i]] = max(dp[b[i]], min(b[i], n));
}
for (int i = sm; i < sz * sz; i ++) {
if (dp[i] >= n * k) {
cout << i - sm;
return 0;
}
}
ex:
cout << "Impossible";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
860 KB |
Output is correct |
2 |
Correct |
15 ms |
860 KB |
Output is correct |
3 |
Correct |
21 ms |
664 KB |
Output is correct |
4 |
Correct |
19 ms |
1032 KB |
Output is correct |
5 |
Correct |
19 ms |
964 KB |
Output is correct |
6 |
Correct |
14 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
17 ms |
860 KB |
Output is correct |
15 |
Correct |
15 ms |
860 KB |
Output is correct |
16 |
Correct |
21 ms |
664 KB |
Output is correct |
17 |
Correct |
19 ms |
1032 KB |
Output is correct |
18 |
Correct |
19 ms |
964 KB |
Output is correct |
19 |
Correct |
14 ms |
860 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
14 ms |
860 KB |
Output is correct |
26 |
Correct |
16 ms |
860 KB |
Output is correct |
27 |
Correct |
10 ms |
604 KB |
Output is correct |
28 |
Correct |
16 ms |
860 KB |
Output is correct |
29 |
Correct |
16 ms |
772 KB |
Output is correct |
30 |
Correct |
19 ms |
1116 KB |
Output is correct |