This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 18;
const int nax = 305;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M, K; cin >> N >> M >> K;
vi A(N); for(auto& x : A) {
cin >> x;
if (x < K) {
cout << "Impossible" << nl;
exit(0-0);
}
}
vi B(M); for(auto& x : B) cin >> x;
int S = accumulate(begin(B), end(B), 0);
int SUM = accumulate(begin(A), end(A), 0);
V<vi> dp(M+1, vi(S+1, -MOD));
dp[0][0] = 0;
for(int i = 0; i < M; i++) {
for(int x = 0; x <= S; x++) {
int amt = min(N, B[i]);
if ((x + B[i]) <= S) dp[i+1][x+B[i]] = max(dp[i+1][x+B[i]], dp[i][x] + amt);
}
}
for(int x = SUM; x <= S; x++) {
// cout << x << " => " << dp[M][x] << nl;
if (dp[M][x] >= N * K) {
cout << x - SUM << nl;
exit(0-0);
}
}
cout << "Impossible" << nl;
exit(0-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... |