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>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
const int mx = 1e5;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, k; cin >> n >> m >> k;
int a[n], b[m], s = 0;
rep (i,0,n-1) {
cin >> a[i];
if (a[i]<k) {
cout << "Impossible\n";
return 0;
}
s += a[i];
}
rep (i,0,m-1) cin >> b[i];
int dp[mx+1] = {}; //for some certain sum, what is the maximum number of different (chef, meal) pairs, if it is at least n*k and the sum is also more than the sum of ai (s), then we should have found an answer, lets see what is the minimum
memset(dp, -1, sizeof(dp));
dp[0] = 0;
rep (i,0,m-1)
rrep (j,mx,b[i])
if (dp[j-b[i]]!=-1) dp[j] = max(dp[j], dp[j-b[i]] + min(b[i], n));
rep (i,s,mx) {
if (dp[i]>=n*k) {
cout << i-s << "\n";
return 0;
}
}
cout << "Impossible\n";
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... |