Submission #375807

#TimeUsernameProblemLanguageResultExecution timeMemory
3758072qbingxuanTwo Dishes (JOI19_dishes)C++14
10 / 100
2800 ms93292 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[2001][2001]; 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 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...