#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define ii pair<int , int>
#define iv pair<ii , ii>
#define iii pair<int , ii>
#define fi first
#define se second
const int inf = 1e9 + 7;
const int MAX_N = 3e2 + 7;
const int MOD = 1e9 + 7;
const int MAX_V = 300 * 301;
int n , m , K;
int f[MAX_N][MAX_N*MAX_N];
int a[MAX_N];
int b[MAX_N];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
cin >> n >> m >> K;
int W = 0 , w = 0;
for (int i = 1 ; i <= n ; i++) {
cin >> a[i];
if (a[i] < K) {
cout << "Impossible";
return 0;
}
W += a[i];
}
for (int i = 1 ; i <= m ; i++) {
cin >> b[i];
w += b[i];
}
if (W > w || K > m) {
cout << "Impossible";
return 0;
}
f[0][0] = 0;
for (int i = 1 ; i <= m ; i++) {
for (int j = 1 ; j <= w ; j++) {
f[i][j] = f[i - 1][j];
if (j - b[i] >= 0) {
f[i][j] = max(f[i][j] , f[i - 1][j - b[i]] + min(b[i] , n));
}
}
}
int ans = inf;
for (int i = W ; i <= w ; i++) {
if (f[m][i] >= n*K) {
ans = min(ans , i - W);
}
}
if (ans == inf) cout << "Impossible";
else cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
68664 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |