#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e6 + 5;
int a[MAXN], b[MAXN];
vector<int> conv;
int tree[2*MAXN];
int query(int node, int start, int end, int l, int r){
if(r < start or end < l){
return 0;
}
if(l <= start and end <= r){
return tree[node];
}
int mid = (start+end)/2;
int p1 = query(2*node, start, mid, l, r);
int p2 = query(2*node +1, mid+1, end, l, r);
return max(p1,p2);
}
void build(int curr, int start, int end){
if(start == end) {
tree[curr] = b[start];
} else {
int mid = (start+end)/2;
build(2*curr, start, mid);
build(2*curr+1, mid+1, end);
tree[curr] = max(tree[2*curr],tree[2*curr+1]);
}
}
void update(int node, int start, int end, int idx, int val){
if(start == end){
b[idx] += val;
tree[node] += val;
} else {
int mid = (start + end)/2;
if(start <= idx and idx <= mid){
update(2*node, start, mid, idx, val);
} else {
update(2*node+1, mid+1, end, idx, val);
}
tree[node] = max(tree[2*node],tree[2*node+1]);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n; cin>>n;
for(int i= 0;i<=n+3;i++){
b[i] = 0;
}
vector<pair<int, pair<int, int>>> vec;
for(int i= 0;i<n;i++){
int t1, t2, t3;
cin>>t1>>t2>>t3;
vec.pb({t1, {t2, t3}});
}
int prefsm[n+2], pref[n+2];
pref[0] = prefsm[0] = 0;
for(int i = 1;i<=n;i++){
pref[i] = pref[i-1] + vec[i-1].sc.sc;
prefsm[i] = prefsm[i-1] + vec[i-1].sc.fr;
}
for(int i= 1;i<=n;i++){
a[i] = vec[i-1].fr-pref[i];
conv.pb(a[i]);
}
sort(all(conv));
conv.resize(unique(all(conv)) - conv.begin());
for(int i=1;i<=n;i++){
a[i] = lower_bound(all(conv), a[i]) - conv.begin();
a[i]++;
}
build(1, 1, n);
int ans = 0;
for(int i = n;i>=1;i--){
if(b[a[i]] == 0){
update(1, 1, n, a[i], i);
}
int vl = vec[i-1].fr-pref[i-1];
int x= upper_bound(all(conv), vl) - conv.begin();
int mx = query(1, 1, n, 1, x);
ans = max(prefsm[mx]-prefsm[i-1], ans);
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
3 ms |
492 KB |
Output is correct |
23 |
Correct |
4 ms |
940 KB |
Output is correct |
24 |
Correct |
4 ms |
940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
3 ms |
492 KB |
Output is correct |
23 |
Correct |
4 ms |
940 KB |
Output is correct |
24 |
Correct |
4 ms |
940 KB |
Output is correct |
25 |
Correct |
4 ms |
940 KB |
Output is correct |
26 |
Correct |
8 ms |
1384 KB |
Output is correct |
27 |
Correct |
8 ms |
1384 KB |
Output is correct |
28 |
Correct |
40 ms |
5088 KB |
Output is correct |
29 |
Correct |
42 ms |
5088 KB |
Output is correct |
30 |
Correct |
86 ms |
9692 KB |
Output is correct |
31 |
Correct |
79 ms |
9692 KB |
Output is correct |
32 |
Correct |
81 ms |
9692 KB |
Output is correct |
33 |
Correct |
80 ms |
9996 KB |
Output is correct |
34 |
Correct |
82 ms |
9692 KB |
Output is correct |
35 |
Correct |
81 ms |
9692 KB |
Output is correct |
36 |
Correct |
84 ms |
9696 KB |
Output is correct |