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>
#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;
for(int L = l;L <= m;L ++){
for(int R = m;R <= r;R ++){
int e = 0 , s = 0;
for(int i = L;i <= R;i ++){
e += d[i];
s += g[i];
}
if(e == x[R] - x[L] + 1){
ans = max(ans , s);
}
}
}
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];
}
x[n + 1] = 1e15;
x[0] = -1e15;
//solve(1 , n);
for(int L = 1;L <= n;L ++){
for(int R = L;R <= n;R ++){
int s = 0 , e = 0;
for(int i = L;i <= R;i ++){
e += d[i];
s += g[i];
}
if(x[R + 1] - x[L - 1] >= e && e >= x[R] - x[L]){
ans = max(ans , s);
}
}
}
cout << ans << endl;
}
Compilation message (stderr)
divide.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |