結果

問題 No.1826 Fruits Collecting
ユーザー tassei903tassei903
提出日時 2022-03-11 17:38:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,245 ms / 2,000 ms
コード長 2,146 bytes
コンパイル時間 1,417 ms
コンパイル使用メモリ 86,652 KB
実行使用メモリ 182,224 KB
最終ジャッジ日時 2023-10-14 00:51:00
合計ジャッジ時間 33,297 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
76,880 KB
testcase_01 AC 115 ms
77,820 KB
testcase_02 AC 117 ms
77,840 KB
testcase_03 AC 117 ms
78,484 KB
testcase_04 AC 95 ms
76,752 KB
testcase_05 AC 491 ms
112,164 KB
testcase_06 AC 788 ms
143,020 KB
testcase_07 AC 565 ms
121,476 KB
testcase_08 AC 152 ms
80,816 KB
testcase_09 AC 785 ms
139,608 KB
testcase_10 AC 545 ms
117,312 KB
testcase_11 AC 538 ms
115,064 KB
testcase_12 AC 266 ms
91,548 KB
testcase_13 AC 195 ms
84,548 KB
testcase_14 AC 220 ms
87,868 KB
testcase_15 AC 1,211 ms
181,336 KB
testcase_16 AC 1,170 ms
181,508 KB
testcase_17 AC 1,155 ms
181,708 KB
testcase_18 AC 1,173 ms
181,308 KB
testcase_19 AC 1,245 ms
181,376 KB
testcase_20 AC 1,212 ms
181,832 KB
testcase_21 AC 1,240 ms
181,608 KB
testcase_22 AC 1,186 ms
181,676 KB
testcase_23 AC 1,216 ms
182,224 KB
testcase_24 AC 1,188 ms
181,956 KB
testcase_25 AC 71 ms
71,148 KB
testcase_26 AC 80 ms
71,260 KB
testcase_27 AC 81 ms
71,480 KB
testcase_28 AC 77 ms
71,128 KB
testcase_29 AC 79 ms
70,972 KB
testcase_30 AC 338 ms
96,892 KB
testcase_31 AC 591 ms
115,584 KB
testcase_32 AC 327 ms
94,228 KB
testcase_33 AC 888 ms
142,988 KB
testcase_34 AC 747 ms
131,340 KB
testcase_35 AC 247 ms
88,536 KB
testcase_36 AC 868 ms
143,444 KB
testcase_37 AC 628 ms
125,672 KB
testcase_38 AC 487 ms
111,092 KB
testcase_39 AC 386 ms
121,748 KB
testcase_40 AC 465 ms
135,632 KB
testcase_41 AC 196 ms
88,452 KB
testcase_42 AC 134 ms
79,224 KB
testcase_43 AC 82 ms
71,376 KB
testcase_44 AC 80 ms
71,176 KB
testcase_45 AC 80 ms
70,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")

#######################################################################

inf = -10**18
class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : max(x,y), default=inf):
        self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2) # 要素を単位元で初期化
        self.f = f
 
    def update(self, i, x):
        i += self.size
        self.dat[i] = self.f(self.dat[i],x)
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
 
    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1
 
            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res
 
    def query2(self):
        s = 1
        #print(self.size)
        while s<self.size:
            #print(s)
            if self.dat[s*2]>self.dat[s*2+1]:
                s = s*2
            else:
                s = s*2+1
        return s-self.size

N = ni()
AB  = []
s = set([0])
for i in range(N):
    t,x,v = na()
    AB.append((x+t,t-x,v,i))
    s.add(t-x)
s = sorted(s)
d = {x:i for i, x in enumerate(s)}
m = len(s)
tree = SegmentTree(m)
tree.update(d[0], 0)
ans = 0
for a,b,v,i in sorted(AB):
    if a < 0:
        continue
    b = d[b]
    z = tree.query(0,b+1)
    #print(a,b,v,z)
    tree.update(b,z+v)
    ans = max(ans, z+v)
print(ans)
0