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 IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
cerr << to_string(h);
if(sizeof ...(t)) cerr << ", ";
DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif
const int INF = 1e9 + 7, mxM = 52, mxC = mxM * mxM * mxM / 2;
void cmax(ll& a, ll b) {
a = max(a, b);
}
int m;
ll l, zero;
V<ll> go(ll* a) {
V<ll> dp(mxC, -1);
dp[0] = 0;
for(int i = 1; i <= m; i++) {
V<ll> ndp(mxC, -1);
for(int j = 0; j < mxC; j++) if(dp[j] != -1) {
for(int take = 0; take <= a[i]; take++)
cmax(ndp[j + take * i], dp[j] + take);
}
swap(dp, ndp);
}
return dp;
}
ll a[mxM], b[mxM];
signed main()
{
IO_OP;
cin >> m >> l;
for(int i = m; i >= 1; i--)
cin >> a[i];
cin >> zero;
for(int i = 1; i <= m; i++)
cin >> b[i];
V<ll> dpa = go(a), dpb = go(b);
ll mx = -1;
for(int i = 0; i < mxC; i++) {
if(i + l < 0 || i + l >= mxC) continue;
int j = i + l;
if(dpa[i] != -1 && dpb[j] != -1)
mx = max(mx, dpa[i] + dpb[j]);
}
if(mx == -1) {
cout << "impossible\n";
return 0;
}
cout << mx + zero << '\n';
}
# | 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... |
# | 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... |