結果

問題 No.165 四角で囲え!
ユーザー chocoruskchocorusk
提出日時 2020-09-18 18:43:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 482 ms / 5,000 ms
コード長 858 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 78,988 KB
最終ジャッジ日時 2023-09-04 09:00:26
合計ジャッジ時間 7,130 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 286 ms
77,712 KB
testcase_01 AC 75 ms
71,412 KB
testcase_02 AC 73 ms
71,488 KB
testcase_03 AC 74 ms
71,224 KB
testcase_04 AC 74 ms
71,260 KB
testcase_05 AC 374 ms
78,100 KB
testcase_06 AC 188 ms
77,800 KB
testcase_07 AC 73 ms
71,544 KB
testcase_08 AC 73 ms
71,256 KB
testcase_09 AC 72 ms
71,508 KB
testcase_10 AC 71 ms
71,288 KB
testcase_11 AC 344 ms
78,988 KB
testcase_12 AC 273 ms
78,896 KB
testcase_13 AC 209 ms
78,140 KB
testcase_14 AC 261 ms
78,700 KB
testcase_15 AC 246 ms
78,372 KB
testcase_16 AC 482 ms
78,352 KB
testcase_17 AC 370 ms
78,536 KB
testcase_18 AC 358 ms
78,816 KB
testcase_19 AC 396 ms
77,920 KB
testcase_20 AC 327 ms
78,236 KB
testcase_21 AC 304 ms
78,352 KB
testcase_22 AC 300 ms
78,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

n, b=map(int, readline().split())
xyp=list(map(int, read().split()))
xs=xyp[::3]
ys=xyp[1::3]
ps=xyp[2::3]
qs=list(zip(xs, ys, ps))
qs.sort()
ans=0
from bisect import bisect_left
for i in range(n):
    if i>0 and qs[i-1][0]==qs[i][0]:
        continue
    z=[]
    for j in range(i, n):
        k=bisect_left(z, qs[j][1:])
        z=z[:k]+[qs[j][1:]]+z[k:]
        if j<n-1 and qs[j+1][0]==qs[j][0]:
            continue
        s=0
        l=0
        for r, q in enumerate(z):
            s+=q[1]
            if r<len(z)-1 and z[r+1][0]==q[0]:
                continue
            while l<=r and (s>b or (l>0 and z[l-1][0]==z[l][0])):
                s-=z[l][1]
                l+=1
            if ans<r-l+1:
                ans=r-l+1
print(ans)
0