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 = 1e5 + 7;
const int mod = 1e9 + 7;
int n;
ll a[N];
ll b[N];
ll d[N];
ll g[N];
ll t[4 * N];
map < int , int > mm;
vector < pair < int , pair < int , int > > > v;
void upd( int x , int l , int r , int pos , ll val )
{
if( l == r ){
t[x] = min( t[x] , val );
return;
}
int m = (l + r) / 2;
if( m >= pos )upd( x * 2 , l , m , pos , val );
else upd( x * 2 + 1 , m + 1 , r , pos , val );
t[x] = min(t[x * 2] , t[x * 2 + 1]);
}
ll get( int x , int l , int r , int tl , int tr )
{
if( tl > tr )return (ll)(1e18);
if( l == tl && r == tr ){
return t[x];
}
int m = (l + r) / 2;
return min( get( x * 2 , l , m , tl , min(tr , m) ) ,
get( x * 2 + 1 , m + 1 , r , max(tl , m + 1) , tr ) );
}
void solve()
{
cin >> n;
for( int i = 1; i <= n; i++ ){
int x,y,z;
cin >> x >> y >> z;
v.push_back({x , {y , z}});
}
for( int i = 1; i <= 4 * n; i++ )t[i] = 1e18;
sort( v.begin() , v.end() );
vector < int > gg;
for( int i = 1; i <= n; i++ ){
d[i] = d[i - 1] + v[i - 1].se.se;
a[i] = d[i] - v[i - 1].fi;
b[i] = d[i - 1] - v[i - 1].fi;
g[i] = g[i - 1] + v[i - 1].se.fi;
gg.push_back(a[i]);
gg.push_back(b[i]);
}
int cnt = 0;
sort( gg.begin() , gg.end() );
for( auto x : gg ){
if( mm.find(x) == mm.end() ){
mm[x] = ++cnt;
}
}
ll ans = 0;
for( int i = 1; i <= n; i++ ){
ans = max( ans , g[i] - g[(get(1 , 1 , cnt , 1 , mm[a[i]]) == 1e18 ? i : get(1 , 1 , cnt , 1 , mm[a[i]]) - 1)] );
upd(1 , 1 , cnt , mm[b[i]] , i);
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int t = 1;//cin >> t;
while( t-- ){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |