結果

問題 No.2741 Balanced Choice
ユーザー D M
提出日時 2025-02-20 11:46:17
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 843 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 67,632 KB
最終ジャッジ日時 2025-02-20 11:46:19
合計ジャッジ時間 1,952 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 2
other RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

from sortedcontainers import SortedDict
from atcoder.segtree import SegTree
import bisect
n,w,d=map(int,input().split())
INF=10**10
D0=SortedDict()
D1=SortedDict()
D0[0]=0
D1[0]=0
for _ in range(n):
    t,w,v=map(int,input().split())
    if t:
        for i,j in D1.items():
            if i-w not in D1:
                D1[i-w]=v+j
            else:
                D1[i-w]=max(D1[i-w],v+j)
    else:
        for i,j in D0.items():
            if i-w not in D0:
                D0[i-w]=v+j
            else:
                D0[i-w]=max(D0[i-w],v+j)
WW=[]
VV=[]
for i,j in D1.items():
    WW.append(-i)
    VV.append(j)
WW=WW[::-1]
VV=VV[::-1]
st=SegTree(max,-1,VV)
ans=0
for i,j in D0.items():
    if -i*2-d<=w:
        l=bisect.bisect_left(WW,-i-d)
        r=bisect.bisect_right(WW,min(-i+d,w))
        ans=max(st.prod(l,r)+j,ans)
print(ans)
0