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>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
int cnt = sizeof...(T);
((std::cerr << "(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\n")));
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
using namespace std;
const int maxn = 200025;
struct Item {
int t, ed, val;
} v[maxn], u[maxn];
int64_t sumv[maxn], sumu[maxn];
int posv[maxn], posu[maxn];
int64_t dp[2005][2005];
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> v[i].t >> v[i].ed >> v[i].val;
for (int i = 1; i <= m; i++)
cin >> u[i].t >> u[i].ed >> u[i].val;
for (int i = 1; i <= n; i++)
sumv[i] = sumv[i-1] + v[i].t;
for (int i = 1; i <= m; i++)
sumu[i] = sumu[i-1] + u[i].t;
for (int i = 1; i <= n; i++)
posv[i] = upper_bound(sumu, sumu+m+1, v[i].ed - sumv[i]) - sumu - 1;
for (int i = 1; i <= m; i++)
posu[i] = upper_bound(sumv, sumv+n+1, u[i].ed - sumu[i]) - sumv - 1;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (i || j)
dp[i][j] = -1e18;
if (i) {
dp[i][j] = max(dp[i][j], dp[i-1][j] + (j <= posv[i]) * v[i].val);
}
if (j) {
dp[i][j] = max(dp[i][j], dp[i][j-1] + (i <= posu[j]) * u[j].val);
}
}
}
cout << dp[n][m] << '\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... |