#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 100;
int n , ans = 0 , SZ;
vector<int> x(N) , g(N) , e(N) , sum_e(N) , sum_g(N);
void solve(int l , int r){
if(l > r){
return;
}
int m = (l + r) / 2;
for(int i = l;i <= r;i ++){
sum_e[i] = sum_e[i - 1] + e[i];
sum_g[i] = sum_g[i - 1] + g[i];
}
vector<pair<int , int>> u;
for(int i = l;i <= r;i ++){
if(i < m){
u.push_back({sum_e[i - 1] - x[i] , i});
}else{
u.push_back({sum_e[i] - x[i] , i});
}
}
sort(u.begin() , u.end());
int mn = 1e15;
for(auto [_value , id] : u){
if(id < m){
mn = min(mn , sum_g[id - 1]);
}else{
ans = max(ans , sum_g[id] - mn);
if(sum_e[id] - sum_e[m - 1] >= x[id] - x[m]){
ans = max(ans , sum_g[id] - sum_g[m - 1]);
}
}
}
for(int i = l;i <= r;i ++){
sum_e[i] = sum_g[i] = 0;
}
solve(l , m - 1);
solve(m + 1 , r);
}
main(){
cin >> n;
for(int i = 1;i <= n;i ++){
cin >> x[i] >> g[i] >> e[i];
}
x[n + 1] = 1e15;
x[0] = -1e15;
solve(1 , n);
cout << ans << endl;
}
Compilation message
divide.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
42 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4188 KB |
Output is correct |
5 |
Correct |
2 ms |
4184 KB |
Output is correct |
6 |
Correct |
3 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
4188 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
2 ms |
4188 KB |
Output is correct |
10 |
Correct |
2 ms |
4188 KB |
Output is correct |
11 |
Correct |
2 ms |
4188 KB |
Output is correct |
12 |
Correct |
2 ms |
4188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4188 KB |
Output is correct |
5 |
Correct |
2 ms |
4184 KB |
Output is correct |
6 |
Correct |
3 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
4188 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
2 ms |
4188 KB |
Output is correct |
10 |
Correct |
2 ms |
4188 KB |
Output is correct |
11 |
Correct |
2 ms |
4188 KB |
Output is correct |
12 |
Correct |
2 ms |
4188 KB |
Output is correct |
13 |
Correct |
2 ms |
4188 KB |
Output is correct |
14 |
Correct |
2 ms |
4188 KB |
Output is correct |
15 |
Correct |
2 ms |
4188 KB |
Output is correct |
16 |
Correct |
2 ms |
4188 KB |
Output is correct |
17 |
Correct |
2 ms |
4188 KB |
Output is correct |
18 |
Correct |
3 ms |
4188 KB |
Output is correct |
19 |
Correct |
2 ms |
4188 KB |
Output is correct |
20 |
Correct |
2 ms |
4188 KB |
Output is correct |
21 |
Correct |
3 ms |
4188 KB |
Output is correct |
22 |
Correct |
3 ms |
4184 KB |
Output is correct |
23 |
Correct |
5 ms |
4444 KB |
Output is correct |
24 |
Correct |
5 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4188 KB |
Output is correct |
5 |
Correct |
2 ms |
4184 KB |
Output is correct |
6 |
Correct |
3 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
4188 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
2 ms |
4188 KB |
Output is correct |
10 |
Correct |
2 ms |
4188 KB |
Output is correct |
11 |
Correct |
2 ms |
4188 KB |
Output is correct |
12 |
Correct |
2 ms |
4188 KB |
Output is correct |
13 |
Correct |
2 ms |
4188 KB |
Output is correct |
14 |
Correct |
2 ms |
4188 KB |
Output is correct |
15 |
Correct |
2 ms |
4188 KB |
Output is correct |
16 |
Correct |
2 ms |
4188 KB |
Output is correct |
17 |
Correct |
2 ms |
4188 KB |
Output is correct |
18 |
Correct |
3 ms |
4188 KB |
Output is correct |
19 |
Correct |
2 ms |
4188 KB |
Output is correct |
20 |
Correct |
2 ms |
4188 KB |
Output is correct |
21 |
Correct |
3 ms |
4188 KB |
Output is correct |
22 |
Correct |
3 ms |
4184 KB |
Output is correct |
23 |
Correct |
5 ms |
4444 KB |
Output is correct |
24 |
Correct |
5 ms |
4444 KB |
Output is correct |
25 |
Correct |
5 ms |
4444 KB |
Output is correct |
26 |
Correct |
8 ms |
4700 KB |
Output is correct |
27 |
Correct |
10 ms |
4672 KB |
Output is correct |
28 |
Correct |
61 ms |
5828 KB |
Output is correct |
29 |
Correct |
56 ms |
5832 KB |
Output is correct |
30 |
Correct |
104 ms |
7620 KB |
Output is correct |
31 |
Correct |
85 ms |
7668 KB |
Output is correct |
32 |
Correct |
83 ms |
7732 KB |
Output is correct |
33 |
Correct |
84 ms |
7644 KB |
Output is correct |
34 |
Correct |
102 ms |
7620 KB |
Output is correct |
35 |
Correct |
89 ms |
7664 KB |
Output is correct |
36 |
Correct |
130 ms |
7736 KB |
Output is correct |