#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 1;
int n , ans = 0;
vector<int> x(N) , g(N) , d(N);
void solve(int l , int r){
if(l > r){
return;
}
int m = (l + r) / 2 , sum_R = 0 , sum_G = 0;
map<int , int> M;
for(int R = m + 1;R <= r;R ++){
sum_R += d[R];
sum_G += g[R];
M[(x[R] - x[m]) - sum_R] = sum_G;
}
//sl + sr = x[R] - x[L] = (x[m] - x[L]) + (x[R] - x[m])
//sl - (x[m] - x[L]) = (x[R] - x[m]) - sr
int sum_L = 0;
sum_G = 0;
for(int L = m;L >= l;L --){
sum_L += d[L];
sum_G += g[L];
if(M.find(sum_L - (x[m] - x[L])) != M.end()){
ans = max(ans , sum_G + M[sum_L - (x[m] - x[L])]);
}
}
if(d[m] == 1){
ans = max(ans , g[m]);
}
solve(l , m - 1);
solve(m + 1 , r);
}
main(){
cin >> n;
for(int i = 1;i <= n;i ++){
cin >> x[i] >> g[i] >> d[i];
}
solve(1 , n);
cout << ans << endl;
}
Compilation message
divide.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |