#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e6 + 5;
ll A[N],C[N],D[N];
ll B[N],E[N],F[N];
map < pii , ll > M;
ll T[N * 4];
ll Lz[N * 4];
void llz(int l,int r,int node) {
T[node] += Lz[node];
if (l != r) {
Lz[node * 2] += Lz[node];
Lz[node * 2 + 1] += Lz[node];
}
Lz[node] = 0;
}
void update(int l,int r,int pos,ll val,int node) {
llz(l,r,node);
if (l == r)
T[node] = val;
else {
int m = (l + r) / 2;
if (pos <= m)
update(l,m,pos,val,node * 2),llz(m+1,r,node * 2 + 1);
else
update(m+1,r,pos,val,node * 2 + 1),llz(l,m,node * 2);
T[node] = max(T[node * 2],T[node * 2 + 1]);
}
}
void Add(int l,int r,int l1,int r1,ll Val,int node) {
llz(l,r,node);
if (l1 <= l && r <= r1) {
Lz[node] += Val;
llz(l,r,node);
} else {
int m = (l + r) / 2;
if (l1 <= m)
Add(l,m,l1,r1,Val,node * 2);
else
llz(l,m,node * 2);
if (m+1<=r1)
Add(m+1,r,l1,r1,Val,node * 2 + 1);
else
llz(m+1,r,node * 2 + 1);
T[node] = max(T[node * 2],T[node * 2 + 1]);
}
}
ll query(int l,int r,int l1,int r1,int node) {
llz(l,r,node);
if (l1 <= l && r <= r1)
return T[node];
int m = (l + r) / 2;
ll ans = -1e18;
if (l1 <= m)
smax(ans,query(l,m,l1,r1,node * 2));
if (m+1<=r1)
smax(ans,query(m+1,r,l1,r1,node * 2 + 1));
return ans;
}
int main(void) {
int n,m;
cin>>n>>m;
for (int i = 1;i <= n;++i)
cin>>A[i]>>C[i]>>D[i],A[i] += A[i - 1];
for (int i = 1;i <= m;++i)
cin>>B[i]>>E[i]>>F[i],B[i] += B[i - 1];
ll bst = 0;
for (int i = 1;i <= n;++i) {
if (A[i] > C[i]) {
continue;
}
int Index = lower_bound(B + 1,B + 1 + m,C[i] - A[i] + 1) - B;
--Index;
if (Index) {
M[mp(i - 1,- 1 - Index)] += D[i];
}
}
for (int i = 1;i <= m;++i) {
if (B[i] > E[i]) {
continue;
}
int Index = lower_bound(A + 1,A + 1 + n,E[i] - B[i] + 1) - A;
--Index;
if (Index) {
M[mp(Index,-i)] -= F[i];
bst += F[i];
}
}
for (auto It : M) {
const int Pos = -It.fi.se;
update(0,m + 1,Pos,query(0,m + 1,0,Pos,1),1);
Add(0,m + 1,0,Pos - 1,It.se,1);
}
cout << query(0,m + 1,0,m + 1,1) + bst << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1020 ms |
38520 KB |
Output is correct |
2 |
Correct |
1028 ms |
41408 KB |
Output is correct |
3 |
Correct |
1136 ms |
49516 KB |
Output is correct |
4 |
Incorrect |
835 ms |
28960 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1020 ms |
38520 KB |
Output is correct |
2 |
Correct |
1028 ms |
41408 KB |
Output is correct |
3 |
Correct |
1136 ms |
49516 KB |
Output is correct |
4 |
Incorrect |
835 ms |
28960 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1020 ms |
38520 KB |
Output is correct |
2 |
Correct |
1028 ms |
41408 KB |
Output is correct |
3 |
Correct |
1136 ms |
49516 KB |
Output is correct |
4 |
Incorrect |
835 ms |
28960 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |