#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
int n, m, k, sm, bad = 0, ans = 1e9, A[305], B[305], dp[305][100005];
int main(){
cin >> n >> m >> k;
FOR(i, 1, n + 1) cin >> A[i], sm += A[i], bad |= (A[i] < k);
FOR(i, 1, m + 1) cin >> B[i];
memset(dp, -0x3f, sizeof(dp)); dp[0][0] = 0;
FOR(i, 1, m + 1) FOR(j, 1, 100005) if (j - B[i] >= 0){
dp[i][j] = dp[i - 1][j - B[i]] + min(B[i], n);
if (j >= sm and dp[i][j] >= n * k) ans = min(ans, j - sm);
}
cout<<((bad or ans == 1e9) ? "Impossible" : to_string(ans))<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
119620 KB |
Output is correct |
2 |
Incorrect |
42 ms |
119632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
119620 KB |
Output is correct |
2 |
Incorrect |
42 ms |
119632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
119640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
119624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
119620 KB |
Output is correct |
2 |
Incorrect |
42 ms |
119632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |