結果

問題 No.1826 Fruits Collecting
コンテスト
ユーザー ああいい
提出日時 2022-01-28 23:09:39
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 641 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 307 ms
コンパイル使用メモリ 84,480 KB
実行使用メモリ 139,300 KB
最終ジャッジ日時 2026-06-04 01:08:31
合計ジャッジ時間 11,464 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())
dat = []
s = set()
for _ in range(N):
    t,x,v = map(int,input().split())
    if t < abs(x):continue
    dat.append((t-x,t,x,v))
    s.add(x+t)
s.add(0)

inf = -10 ** 18
D = {v:i for i,v in enumerate(sorted(s))}
n = len(D)
bit = [inf] * (n+1)
def add(i,x):
    while i <= n:
        bit[i] = max(bit[i],x)
        i += i & -i
def getmax(i):
    ans = 0
    while i > 0:
        ans = max(ans,bit[i])
        i -= i & -i
    return ans

dat.sort(key = lambda x:x[0])
add(D[0] + 1,0)
for d,t,x,v in dat:
    a = D[x + t] + 1
    b = getmax(a)
    tmp = b + v
    add(a,tmp)
ans = getmax(n)
if ans < 0:
    ans = 0
print(ans)
0