using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; i++)
typedef vector<int> vi;
typedef vector<vi> vvi;
int n, m, k;
vi a, b;
int main() {
cin >> n >> m >> k;
a.resize(n);
b.resize(m);
rep(i,0,n) cin >> a[i];
rep(i,0,m) cin >> b[i];
rep(i,0,n) if (a[i] < k) {
cout << "Impossible\n";
exit(0);
}
// dp[i] = num
// dp[i] = maximum sum2 with sum1 = i?
const int maxs = 330*330;
vvi dp(2, vi(maxs, -1));
dp[0][0] = 0; dp[1][0] = 0;
rep(i,0,m) {
int sum1 = b[i];
int sum2 = min(b[i], n);
int i1 = i&1;
rep(j,0,maxs - sum1) {
if (dp[i1][j] == -1) continue;
dp[i1^1][j + sum1] = max(dp[i1^1][j + sum1], dp[i1][j] + sum2);
}
}
int minimi = n * k;
int start = 0;
rep(i,0,n) start += a[i];
rep(i, start, maxs) {
if (dp[0][i] >= minimi || dp[1][i] >= minimi) {
cout << (i - start) << endl;
exit(0);
}
}
cout << "Impossible" << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1580 KB |
Output is correct |
6 |
Correct |
0 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1580 KB |
Output is correct |
6 |
Correct |
0 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
2 ms |
1620 KB |
Output is correct |
10 |
Correct |
2 ms |
1492 KB |
Output is correct |
11 |
Correct |
2 ms |
1492 KB |
Output is correct |
12 |
Correct |
2 ms |
1576 KB |
Output is correct |
13 |
Incorrect |
2 ms |
1492 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
1492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1492 KB |
Output is correct |
2 |
Incorrect |
4 ms |
1492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1580 KB |
Output is correct |
6 |
Correct |
0 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
2 ms |
1620 KB |
Output is correct |
10 |
Correct |
2 ms |
1492 KB |
Output is correct |
11 |
Correct |
2 ms |
1492 KB |
Output is correct |
12 |
Correct |
2 ms |
1576 KB |
Output is correct |
13 |
Incorrect |
2 ms |
1492 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |