結果

問題 No.1826 Fruits Collecting
ユーザー chineristACchineristAC
提出日時 2022-06-19 14:25:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 820 ms / 2,000 ms
コード長 2,126 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 192,352 KB
最終ジャッジ日時 2024-04-19 19:59:34
合計ジャッジ時間 20,115 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
70,272 KB
testcase_01 AC 79 ms
78,232 KB
testcase_02 AC 84 ms
78,188 KB
testcase_03 AC 86 ms
78,348 KB
testcase_04 AC 58 ms
70,016 KB
testcase_05 AC 353 ms
121,432 KB
testcase_06 AC 527 ms
147,584 KB
testcase_07 AC 393 ms
126,056 KB
testcase_08 AC 119 ms
81,280 KB
testcase_09 AC 513 ms
148,308 KB
testcase_10 AC 356 ms
122,368 KB
testcase_11 AC 361 ms
122,368 KB
testcase_12 AC 180 ms
93,852 KB
testcase_13 AC 138 ms
84,648 KB
testcase_14 AC 159 ms
89,184 KB
testcase_15 AC 810 ms
191,488 KB
testcase_16 AC 804 ms
191,616 KB
testcase_17 AC 807 ms
191,624 KB
testcase_18 AC 791 ms
191,524 KB
testcase_19 AC 804 ms
191,616 KB
testcase_20 AC 820 ms
191,580 KB
testcase_21 AC 803 ms
191,688 KB
testcase_22 AC 796 ms
191,744 KB
testcase_23 AC 810 ms
191,968 KB
testcase_24 AC 805 ms
192,352 KB
testcase_25 AC 42 ms
56,320 KB
testcase_26 AC 42 ms
56,320 KB
testcase_27 AC 41 ms
56,448 KB
testcase_28 AC 40 ms
56,064 KB
testcase_29 AC 40 ms
56,192 KB
testcase_30 AC 188 ms
99,572 KB
testcase_31 AC 331 ms
121,828 KB
testcase_32 AC 220 ms
97,280 KB
testcase_33 AC 570 ms
148,480 KB
testcase_34 AC 509 ms
137,728 KB
testcase_35 AC 167 ms
89,900 KB
testcase_36 AC 570 ms
147,580 KB
testcase_37 AC 410 ms
134,940 KB
testcase_38 AC 295 ms
116,112 KB
testcase_39 AC 279 ms
121,600 KB
testcase_40 AC 329 ms
130,944 KB
testcase_41 AC 133 ms
88,520 KB
testcase_42 AC 98 ms
78,720 KB
testcase_43 AC 44 ms
56,320 KB
testcase_44 AC 51 ms
56,052 KB
testcase_45 AC 41 ms
56,320 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.buffer.readline()
mi = lambda :map(int,input().split())
li = lambda :list(mi())


if 0:
    N,V = mi()
    T = li()
    X = li()
    item = [(V*t,x) for t,x in zip(T,X)]
else:
    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)
if 0:
    for t,x in item:
        if t-x < 0:
            continue
        tmp = dp.query(0,comp[t+x]+1) + 1
        dp.update(comp[t+x],tmp)
else:
    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