제출 #572177

#제출 시각아이디문제언어결과실행 시간메모리
572177sidonTwo Dishes (JOI19_dishes)C++17
100 / 100
3325 ms409584 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; for(int i = 1; i <= N; ++i) { g[i][M] += 0; int cur {}, l {}; auto fix = [&](int j) { auto f = s.upper_bound(j); while(f != s.end() && f->first <= M && f->second <= 0) { auto nx = next(f) == end(s) ? M + 1 : next(f)->first; s[nx] += f->second; f = s.erase(f); } }; for(auto [r, val] : g[i]) cur += val; for(auto [r, val] : g[i]) { s[l] += cur; s[r+1] -= cur; cur -= val; l = r + 1; } for(auto [r, val] : g[i]) fix(r); } 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...