//In The Name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int N = 300 + 10;
const int M = 90000 + 10;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 10;
int a[N], b[N], dp[N][M];
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
int sum = 0, mn = inf;
for (int i = 1; i <= n; i ++)
cin >> a[i], sum += a[i], mn = min(mn, a[i]);
for (int i = 1; i <= m; i ++)
cin >> b[i];
if (mn < k)
return cout << "Impossible", 0;
for (int i = 0; i < N; i ++)
for (int j = 0; j < M; j ++)
dp[i][j] = -inf;
dp[0][0] = 0;
for (int i = 1; i <= m; i ++){
for (int j = 0; j < M; j ++){
dp[i][j] = dp[i - 1][j];
if (b[i] <= j && dp[i - 1][j - b[i]] != -inf)
dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + min(b[i], n));
}
}
int ans = inf;
for (int j = sum; j < M; j ++)
if (n * k <= dp[m][j])
ans = min(ans, j - sum);
if (ans == inf)
return cout << "Impossible", 0;
cout << ans;
return 0;
}
//codam paride az cms
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
109548 KB |
Output is correct |
2 |
Correct |
67 ms |
109548 KB |
Output is correct |
3 |
Correct |
70 ms |
109548 KB |
Output is correct |
4 |
Correct |
67 ms |
109548 KB |
Output is correct |
5 |
Correct |
67 ms |
109548 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
66 ms |
109548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
109548 KB |
Output is correct |
2 |
Correct |
67 ms |
109548 KB |
Output is correct |
3 |
Correct |
70 ms |
109548 KB |
Output is correct |
4 |
Correct |
67 ms |
109548 KB |
Output is correct |
5 |
Correct |
67 ms |
109548 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
66 ms |
109548 KB |
Output is correct |
9 |
Correct |
69 ms |
109548 KB |
Output is correct |
10 |
Correct |
68 ms |
109548 KB |
Output is correct |
11 |
Correct |
69 ms |
109548 KB |
Output is correct |
12 |
Correct |
69 ms |
109548 KB |
Output is correct |
13 |
Correct |
73 ms |
109548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
109676 KB |
Output is correct |
2 |
Correct |
100 ms |
109548 KB |
Output is correct |
3 |
Correct |
112 ms |
109676 KB |
Output is correct |
4 |
Correct |
113 ms |
109676 KB |
Output is correct |
5 |
Correct |
109 ms |
109548 KB |
Output is correct |
6 |
Correct |
96 ms |
109548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
109736 KB |
Output is correct |
2 |
Correct |
77 ms |
109548 KB |
Output is correct |
3 |
Correct |
73 ms |
109548 KB |
Output is correct |
4 |
Correct |
79 ms |
109676 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
109548 KB |
Output is correct |
2 |
Correct |
67 ms |
109548 KB |
Output is correct |
3 |
Correct |
70 ms |
109548 KB |
Output is correct |
4 |
Correct |
67 ms |
109548 KB |
Output is correct |
5 |
Correct |
67 ms |
109548 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
66 ms |
109548 KB |
Output is correct |
9 |
Correct |
69 ms |
109548 KB |
Output is correct |
10 |
Correct |
68 ms |
109548 KB |
Output is correct |
11 |
Correct |
69 ms |
109548 KB |
Output is correct |
12 |
Correct |
69 ms |
109548 KB |
Output is correct |
13 |
Correct |
73 ms |
109548 KB |
Output is correct |
14 |
Correct |
105 ms |
109676 KB |
Output is correct |
15 |
Correct |
100 ms |
109548 KB |
Output is correct |
16 |
Correct |
112 ms |
109676 KB |
Output is correct |
17 |
Correct |
113 ms |
109676 KB |
Output is correct |
18 |
Correct |
109 ms |
109548 KB |
Output is correct |
19 |
Correct |
96 ms |
109548 KB |
Output is correct |
20 |
Correct |
73 ms |
109736 KB |
Output is correct |
21 |
Correct |
77 ms |
109548 KB |
Output is correct |
22 |
Correct |
73 ms |
109548 KB |
Output is correct |
23 |
Correct |
79 ms |
109676 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
96 ms |
109548 KB |
Output is correct |
26 |
Correct |
104 ms |
109676 KB |
Output is correct |
27 |
Correct |
90 ms |
109548 KB |
Output is correct |
28 |
Correct |
102 ms |
109548 KB |
Output is correct |
29 |
Correct |
103 ms |
109548 KB |
Output is correct |
30 |
Correct |
109 ms |
109548 KB |
Output is correct |