This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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
#define int long long
const int inf = 1e18 + 7;
const int MAX_N = 41;
const int MOD = 1e9 + 7;
int n , m , K;
int f[41][41][1600];
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;
}
for (int i = 1 ; i <= m ; i++) {
f[i - 1][0][0] = 1;
for (int j = 1 ; j <= m ; j++) {
for (int k = b[i] ; k <= w ; k++) {
if (f[i - 1][j - 1][k - b[i]]) {
f[i][j][k] = 1;
}
}
}
for (int j = 1 ; j <= m ; j++) {
for (int k = 1 ; k <= w ; k++) {
if (f[i - 1][j][k]) {
f[i][j][k] = 1;
}
}
}
}
int ans = inf;
for (int i = K ; i <= max(K , m); i++) {
for (int j = W ; j <= w ; j++) {
if (f[m][i][j])
ans = min(ans , j - W);
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |