Submission #167201

#TimeUsernameProblemLanguageResultExecution timeMemory
167201muhammad_hokimiyonDivide and conquer (IZhO14_divide)C++14
0 / 100
4 ms504 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...