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>
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 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... |