結果

問題 No.1826 Fruits Collecting
ユーザー chineristACchineristAC
提出日時 2022-01-28 23:26:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 972 ms / 2,000 ms
コード長 1,855 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 186,372 KB
最終ジャッジ日時 2023-08-28 22:03:47
合計ジャッジ時間 25,394 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
79,208 KB
testcase_01 AC 159 ms
81,800 KB
testcase_02 AC 158 ms
81,692 KB
testcase_03 AC 162 ms
82,012 KB
testcase_04 AC 135 ms
79,492 KB
testcase_05 AC 480 ms
121,400 KB
testcase_06 AC 677 ms
151,100 KB
testcase_07 AC 519 ms
129,788 KB
testcase_08 AC 192 ms
84,284 KB
testcase_09 AC 661 ms
148,460 KB
testcase_10 AC 514 ms
130,760 KB
testcase_11 AC 474 ms
112,060 KB
testcase_12 AC 279 ms
94,292 KB
testcase_13 AC 218 ms
88,436 KB
testcase_14 AC 257 ms
93,328 KB
testcase_15 AC 972 ms
185,892 KB
testcase_16 AC 957 ms
185,780 KB
testcase_17 AC 947 ms
185,776 KB
testcase_18 AC 939 ms
185,480 KB
testcase_19 AC 965 ms
185,552 KB
testcase_20 AC 953 ms
185,884 KB
testcase_21 AC 953 ms
185,572 KB
testcase_22 AC 968 ms
185,824 KB
testcase_23 AC 953 ms
186,372 KB
testcase_24 AC 943 ms
186,016 KB
testcase_25 AC 113 ms
74,544 KB
testcase_26 AC 112 ms
74,584 KB
testcase_27 AC 114 ms
74,668 KB
testcase_28 AC 114 ms
74,236 KB
testcase_29 AC 113 ms
74,328 KB
testcase_30 AC 288 ms
102,900 KB
testcase_31 AC 415 ms
112,876 KB
testcase_32 AC 325 ms
101,644 KB
testcase_33 AC 728 ms
133,536 KB
testcase_34 AC 666 ms
140,900 KB
testcase_35 AC 264 ms
93,872 KB
testcase_36 AC 730 ms
151,076 KB
testcase_37 AC 529 ms
118,744 KB
testcase_38 AC 427 ms
123,292 KB
testcase_39 AC 402 ms
123,940 KB
testcase_40 AC 470 ms
135,228 KB
testcase_41 AC 222 ms
89,732 KB
testcase_42 AC 167 ms
82,488 KB
testcase_43 AC 112 ms
74,628 KB
testcase_44 AC 113 ms
74,624 KB
testcase_45 AC 114 ms
74,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.size = n
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = self.segfunc(self.tree[k],x)
        while k > 1:
            k >>= 1
            self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1])

    def query(self, l, r):
        if r==self.size:
            r = self.num

        res = self.ide_ele

        l += self.num
        r += self.num
        right = []
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                right.append(self.tree[r-1])
            l >>= 1
            r >>= 1

        for e in right[::-1]:
            res = self.segfunc(res,e)
        return res

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N = int(input())
item = [tuple(mi()) for i in range(N)]
item.sort(key=lambda x:x[0]-x[1])

val = set([x[0]+x[1] for x in item]+[0])
comp = {e:i for i,e in enumerate(sorted(val))}
n = len(comp)

dp = SegmentTree([-10**17]*n,max,-10**17)
dp.update(comp[0],0)
for t,x,v in item:
    if t-x < 0:
        continue
    tmp = dp.query(0,comp[t+x]+1) + v
    dp.update(comp[t+x],tmp)

print(dp.query(0,n))
0