#include <bits/stdc++.h>
using namespace std;
const int MX = 405;
const int INF = 1e9 + 7;
int N, M, K, a[MX], b[MX], dp[2][MX * MX], tot = 0;
void chmax(int& a, int b){
if(b > a) a = b;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M >> K;
for(int i = 0; i < N; i++) cin >> a[i];
for(int j = 0; j < M; j++) cin >> b[j];
bool f = true;
for(int i = 0; i < N; i++){
if(a[i] < K) f = false;
tot += a[i];
}
if(!f){
cout << "Impossible\n";
return 0;
}
for(int j = 0; j <= 300 * M; j++) dp[0][j] = -INF;
dp[0][0] = 0;
int id = 1;
for(int i = 0; i < M; i++){
for(int j = 0; j <= 300 * M; j++) dp[id][j] = -INF;
for(int j = 0; j <= 300 * M; j++){
chmax(dp[id][j + b[i]], dp[id ^ 1][j] + min(b[i], N));
chmax(dp[id][j], dp[id ^ 1][j]);
}
id ^= 1;
}
for(int j = tot; j <= 300 * M; j++){
if(dp[id ^ 1][j] >= N * K){
cout << j - tot << '\n';
return 0;
}
}
cout << "Impossible\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
948 KB |
Output is correct |
2 |
Correct |
21 ms |
836 KB |
Output is correct |
3 |
Correct |
45 ms |
1040 KB |
Output is correct |
4 |
Correct |
35 ms |
992 KB |
Output is correct |
5 |
Correct |
33 ms |
980 KB |
Output is correct |
6 |
Correct |
17 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
428 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
26 ms |
948 KB |
Output is correct |
15 |
Correct |
21 ms |
836 KB |
Output is correct |
16 |
Correct |
45 ms |
1040 KB |
Output is correct |
17 |
Correct |
35 ms |
992 KB |
Output is correct |
18 |
Correct |
33 ms |
980 KB |
Output is correct |
19 |
Correct |
17 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
428 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
17 ms |
724 KB |
Output is correct |
26 |
Correct |
23 ms |
900 KB |
Output is correct |
27 |
Correct |
11 ms |
712 KB |
Output is correct |
28 |
Correct |
23 ms |
852 KB |
Output is correct |
29 |
Correct |
25 ms |
912 KB |
Output is correct |
30 |
Correct |
43 ms |
1028 KB |
Output is correct |