結果

問題 No.1826 Fruits Collecting
ユーザー momoyuumomoyuu
提出日時 2023-10-26 14:06:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 1,248 bytes
コンパイル時間 4,365 ms
コンパイル使用メモリ 263,160 KB
実行使用メモリ 23,268 KB
最終ジャッジ日時 2023-10-26 14:06:56
合計ジャッジ時間 14,928 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 3 ms
4,372 KB
testcase_03 AC 3 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 94 ms
12,164 KB
testcase_06 AC 158 ms
20,896 KB
testcase_07 AC 105 ms
13,016 KB
testcase_08 AC 11 ms
4,428 KB
testcase_09 AC 174 ms
14,912 KB
testcase_10 AC 102 ms
12,632 KB
testcase_11 AC 98 ms
12,296 KB
testcase_12 AC 37 ms
7,484 KB
testcase_13 AC 18 ms
5,224 KB
testcase_14 AC 28 ms
6,004 KB
testcase_15 AC 251 ms
23,268 KB
testcase_16 AC 255 ms
23,268 KB
testcase_17 AC 256 ms
23,268 KB
testcase_18 AC 252 ms
23,268 KB
testcase_19 AC 254 ms
23,268 KB
testcase_20 AC 264 ms
23,268 KB
testcase_21 AC 256 ms
23,268 KB
testcase_22 AC 251 ms
23,268 KB
testcase_23 AC 251 ms
23,268 KB
testcase_24 AC 251 ms
23,268 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 2 ms
4,372 KB
testcase_27 AC 2 ms
4,372 KB
testcase_28 AC 2 ms
4,372 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 46 ms
7,976 KB
testcase_31 AC 98 ms
12,596 KB
testcase_32 AC 46 ms
7,928 KB
testcase_33 AC 171 ms
21,088 KB
testcase_34 AC 138 ms
14,048 KB
testcase_35 AC 28 ms
6,016 KB
testcase_36 AC 166 ms
20,968 KB
testcase_37 AC 91 ms
10,780 KB
testcase_38 AC 63 ms
9,232 KB
testcase_39 AC 103 ms
15,752 KB
testcase_40 AC 130 ms
15,984 KB
testcase_41 AC 29 ms
6,200 KB
testcase_42 AC 6 ms
4,372 KB
testcase_43 AC 2 ms
4,372 KB
testcase_44 AC 2 ms
4,372 KB
testcase_45 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#include<atcoder/segtree>

ll op(ll a,ll b){
    return max(a,b);
}
ll e(){
    return -1e18;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    vector<ll> dx;
    vector<ll> t(n),x(n),v(n);
    for(int i = 0;i<n;i++){
        cin>>t[i]>>x[i]>>v[i];
        dx.push_back(t[i]-x[i]);
        dx.push_back(x[i]+t[i]);
    }
    dx.push_back(0);
    vector<int> idx(n);
    for(int i = 0;i<n;i++) idx[i] = i;
    sort(dx.begin(),dx.end());
    dx.erase(unique(dx.begin(),dx.end()),dx.end());
    sort(idx.begin(),idx.end(),[&](int i,int j){
        if(t[i]+x[i]==t[j]+x[j]) return t[i] - x[i] < t[j] - x[j];
        return t[i] + x[i] < t[j] + x[j];});
    ll ans = 0;
    int m = dx.size();
    atcoder::segtree<ll,op,e> seg(m);
    int nk = lower_bound(dx.begin(),dx.end(),0) - dx.begin();
    for(int i = 0;i<n;i++){
        int ni = idx[i];
        int nni = lower_bound(dx.begin(),dx.end(),t[ni]-x[ni]) - dx.begin();
        ll now = seg.prod(0,nni+1) + v[ni];
        if(-t[ni]<=x[ni]&&x[ni]<=t[ni]) now = op(now,v[ni]);
        seg.set(nni,op(seg.get(nni),now));
        ans = max(ans,now);
    }
    cout<<ans<<endl;
    
}
0