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>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 300 + 5;
const int inf = 1e9;
const int mod = 1e9 + 7;
int a[N], b[N], dp[N * N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
int moze = 1;
int sa, sb;
sa = sb = 0;
for (int i = 1; i <= n; i++) {
sa += a[i];
if (a[i] < k) moze = 0;
}
for (int i = 1; i <= m; i++) sb += b[i];
if (moze == 0) {
cout << "Impossible" << en;
return 0;
}
for (int i = 1; i < N * N; i++) dp[i] = -inf;
for (int i = 1; i <= m; i++) {
for (int j = N * N - 1; j >= b[i]; j--) smax(dp[j], dp[j - b[i]] + min(b[i], n));
}
for (int i = sa; i < N; i++) {
if (dp[i] >= n * k) {
cout << i - sa << en;
return 0;
}
}
cout << "Impossible" << en;
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... |