Submission #375816

#TimeUsernameProblemLanguageResultExecution timeMemory
3758162qbingxuanTwo Dishes (JOI19_dishes)C++14
10 / 100
10030 ms15980 KiB
#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; int64_t ed; int val; } v[maxn], u[maxn]; int64_t sumv[maxn], sumu[maxn]; int posv[maxn], posu[maxn]; int64_t dp[maxn]; 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 j = 1; j <= m; j++) dp[j] = dp[j-1] + (posu[j] >= 0 ? u[j].val : 0); for (int i = 0; i <= n; i++) { for (int j = 0; j <= posv[i]; j++) dp[j] += v[i].val; for (int j = 1; j <= m; j++) dp[j] = max(dp[j], dp[j-1] + (i <= posu[j] ? u[j].val : 0)); } cout << dp[m] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...