#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 300 + 5;
const int inf = 1e9;
const int mod = 1e9 + 7;
int a[N], b[N], dp[N * N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
int moze = 1;
int sa, sb;
sa = sb = 0;
for (int i = 1; i <= n; i++) {
sa += a[i];
if (a[i] < k) moze = 0;
}
for (int i = 1; i <= m; i++) sb += b[i];
moze &= sa <= sb;
moze &= m >= k;
if (moze == 0) {
cout << "Impossible" << en;
return 0;
}
for (int i = 1; i < N * N; i++) dp[i] = -inf;
for (int i = 1; i <= m; i++) {
for (int j = N * N - 1; j >= b[i]; j--) smax(dp[j], dp[j - b[i]] + min(b[i], n));
}
for (int i = sa; i < N; i++) {
if (dp[i] >= n * k) {
cout << i - sa << en;
return 0;
}
}
assert(false);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Runtime error |
2 ms |
1236 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Runtime error |
2 ms |
1236 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
1200 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1236 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Runtime error |
2 ms |
1236 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |