#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define ll long long
using namespace std;
const int N = 4e5 + 7;
const int mod = 1e9 + 7;
int n;
ll a[N];
ll b[N];
ll d[N];
ll g[N];
ll t[N];
map < ll , int > m;
vector < pair < ll , pair < ll , ll > > > v;
ll get( int x , int l , int r , int tl , int tr )
{
if( tl > tr )return 1e18;
if( l == tl && r == tr ){
return t[x];
}
int mid = (l + r) / 2;
return min( get( x * 2 , l , mid , tl , min(tr , mid) ) ,
get( x * 2 + 1 , mid + 1 , r , max(tl , mid + 1) , tr ) );
}
void upd( int x , int l , int r , int pos , ll val )
{
if( l == r ){
t[x] = min( t[x] , val );
return;
}
int mid = (l + r) / 2;
if( mid >= pos )upd( x * 2 , l , mid , pos , val );
else upd( x * 2 + 1 , mid + 1 , r , pos , val );
t[x] = min( t[x * 2] , t[x * 2 + 1] );
}
void solve()
{
cin >> n;
ll ans = 0;
for( int i = 1; i <= n; i++ ){
ll x,y,z;
cin >> x >> y >> z;
ans = max( ans , y );
v.push_back({x , {y , z}});
}
for( int i = 1; i <= 4 * n; i++ ){
t[i] = 1e18;
}
sort( v.begin() , v.end() );
vector < int > o;
for( int i = 0; i < (int)v.size(); i++ ){
d[i] = v[i].se.se;
if( i > 0 )d[i] += d[i - 1] , g[i] = g[i - 1];
g[i] += v[i].se.fi;
a[i] = d[i - 1] - v[i].fi;
b[i] = d[i] - v[i].fi;
o.push_back(a[i]);
o.push_back(b[i]);
}
int G = 0;
sort( o.begin() , o.end() );
for( int i = 0; i < (int)o.size(); i++ ){
if( m.find(o[i]) == m.end() ){
m[o[i]] = ++G;
}
}
for( int i = 0; i < (int)v.size(); i++ ){
ll x = get( 1 , 1 , G , 1 , m[b[i]] );
//cout << i << " " << x << " " << m[a[i]] << " " << m[b[i]] << " " << g[i] << "\n";
ans = max( ans , g[i] - x );
upd( 1 , 1 , G , m[a[i]] , (i > 0 ? g[i - 1] : 0) );
}
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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1592 KB |
Output is correct |
2 |
Correct |
17 ms |
2936 KB |
Output is correct |
3 |
Incorrect |
19 ms |
3572 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |