답안 #168163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168163 2019-12-11T17:26:21 Z muhammad_hokimiyon 금 캐기 (IZhO14_divide) C++14
0 / 100
109 ms 10736 KB
#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;
    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 > 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;
        }
    }
    for( int i = 1; i <= n; i++ ){
        //cout << get(1 , 1 , cnt , 1 , mm[a[i]]) << " " << mm[a[i]] << " " << mm[b[i]] << "\n";
        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();
    }
}
# 결과 실행 시간 메모리 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 376 KB Output is correct
3 Incorrect 2 ms 428 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1400 KB Output is correct
2 Correct 15 ms 2488 KB Output is correct
3 Correct 16 ms 2488 KB Output is correct
4 Incorrect 109 ms 10736 KB Output isn't correct
5 Halted 0 ms 0 KB -