Submission #572172

#TimeUsernameProblemLanguageResultExecution timeMemory
572172sidonTwo Dishes (JOI19_dishes)C++17
0 / 100
303 ms72664 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios::sync_with_stdio(0), cin.tie(0); int N, M; cin >> N >> M; int A[N], S[N], P[N]; int B[M], T[M], Q[M]; for(int i = 0; i < N; ++i) { cin >> A[i] >> S[i] >> P[i]; if(i) A[i] += A[i-1]; } for(int i = 0; i < M; ++i) { cin >> B[i] >> T[i] >> Q[i]; if(i) B[i] += B[i-1]; } map<int, int> g[N+1] {{{0, 0}}}; int ans {}; for(int i = 0; i < N; ++i) if(S[i] >= A[i]) { S[i] = upper_bound(B, B + M, S[i] - A[i]) - B; g[i+1][S[i]] += P[i]; } for(int i = 0; i < M; ++i) if(T[i] >= B[i]) { T[i] = upper_bound(A, A + N, T[i] - B[i]) - A; if(T[i] < N) g[T[i]+1][i] -= Q[i]; ans += Q[i]; } map<int, int> s {{1, -1e17}}; for(int i = 1; i <= N; ++i) { g[i][M+1] = 0; int cur {}, last = 1e17, l {}; auto p = begin(g[i-1]); for(auto [r, val] : g[i]) cur += val; for(auto [r, val] : g[i]) { s[l] += cur; s[r+1] -= cur; auto fix = [&](int j) { auto f = s.upper_bound(j); while(f != s.end() && f->first <= r && f->second <= 0) { auto nx = next(f) == end(s) ? r + 1 : next(f)->first; s[nx] += f->second; f = s.erase(f); } }; if(s[l] < 0) { s[l+1] += s[l]; s[l] = 0; fix(l); } cur -= last = val; for(; p != end(g[i-1]) && p->first <= r; p++) fix(p->first); l = r + 1; } } for(int i = 0; i <= M; ++i) ans += s[i]; cout << ans; }
#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...