#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 300;
int const inf = 1000000000;
int v[5 + nmax], v2[5 + nmax];
bitset<5 + nmax * nmax> dpinit, dp[5 + nmax];
int dist[5 + nmax * nmax];
int main()
{
int n, k, m;
cin >> n >> m >> k;
int sum = 0;
for(int i = 1;i <= n; i++) {
cin >> v[i];
sum += v[i];
if(v[i] < k) {
cout << "Impossible";
return 0;
}
}
dpinit[0] = 1;
int ptr = 0;
dp[0][0] = 1;
for(int i = 1;i <= m; i++) {
cin >> v2[i];
if(v2[i] < n)
dpinit |= (dpinit<<v2[i]);
else{
for(int j = ptr; 0 <= j; j--)
dp[j + 1] |= (dp[j]<<v2[i]);
++ptr;
}
}
dist[n * nmax + 1] = inf;
for(int i = n * nmax; 0 <= i; i--){
if(dpinit[i] == 1)
dist[i] = 0;
else
dist[i] = dist[i + 1] + 1;
}
int result = inf;
for(int i = 0; i <= ptr; i++){
for(int j = 0; j <= i * nmax; j++){
if(dp[i][j] == 1){
int diff = MAX(n * k - i * n, sum - j);
if(diff <= 0)
result = MIN(result, j - sum);
else
result = MIN(result, dist[diff] + diff + j - sum);
}
}
}
if(1 + nmax * nmax <= result)
cout << "Impossible";
else
cout << result;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
3 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
760 KB |
Output is correct |
2 |
Correct |
4 ms |
760 KB |
Output is correct |
3 |
Correct |
4 ms |
760 KB |
Output is correct |
4 |
Correct |
36 ms |
1912 KB |
Output is correct |
5 |
Correct |
7 ms |
1016 KB |
Output is correct |
6 |
Correct |
4 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
760 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
3 ms |
760 KB |
Output is correct |
14 |
Correct |
4 ms |
760 KB |
Output is correct |
15 |
Correct |
4 ms |
760 KB |
Output is correct |
16 |
Correct |
4 ms |
760 KB |
Output is correct |
17 |
Correct |
36 ms |
1912 KB |
Output is correct |
18 |
Correct |
7 ms |
1016 KB |
Output is correct |
19 |
Correct |
4 ms |
760 KB |
Output is correct |
20 |
Correct |
6 ms |
760 KB |
Output is correct |
21 |
Correct |
3 ms |
632 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
108 ms |
2900 KB |
Output is correct |
26 |
Correct |
144 ms |
3348 KB |
Output is correct |
27 |
Correct |
25 ms |
1528 KB |
Output is correct |
28 |
Correct |
51 ms |
2164 KB |
Output is correct |
29 |
Correct |
162 ms |
3320 KB |
Output is correct |
30 |
Correct |
60 ms |
2424 KB |
Output is correct |