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>
#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define LL long long
using namespace std;
const int N = 2e5 + 7;
const int mod = 1e9 + 7;
int n;
int x[N];
LL g[N];
LL d[N];
LL pg[N];
LL pd[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
cin >> n;
LL ans = 0;
for( int i = 1; i <= n; i++ ){
cin >> x[i] >> g[i] >> d[i];
ans = max( ans , g[i] );
}
for( int i = 1; i <= n; i++ ){
pg[i] = pg[i - 1] + g[i];
pd[i] = pd[i - 1] + d[i];
}
for( int i = 1; i <= n; i++ ){
int l = i , r = n;
while( r - l > 3 ){
int m1 = l + (r - l) / 3;
int m2 = r - (r - l) / 2;
if( pd[m1] - pd[i - 1] <= x[m2] - x[i] ){
l = m1;
}
else r = m2;
}
for( ; l <= r; l++ ){
if( x[l] - x[i] <= pd[l] - pd[i - 1] ){
ans = max( ans , pg[l] - pg[i - 1] );
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |