結果

問題 No.165 四角で囲え!
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-20 16:14:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,669 ms / 5,000 ms
コード長 961 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 78,324 KB
最終ジャッジ日時 2024-05-01 03:27:29
合計ジャッジ時間 11,945 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 515 ms
78,012 KB
testcase_01 AC 39 ms
54,248 KB
testcase_02 AC 36 ms
55,240 KB
testcase_03 AC 39 ms
54,316 KB
testcase_04 AC 38 ms
54,860 KB
testcase_05 AC 696 ms
77,828 KB
testcase_06 AC 280 ms
77,032 KB
testcase_07 AC 39 ms
54,436 KB
testcase_08 AC 39 ms
54,768 KB
testcase_09 AC 38 ms
53,760 KB
testcase_10 AC 37 ms
55,592 KB
testcase_11 AC 470 ms
78,036 KB
testcase_12 AC 311 ms
78,136 KB
testcase_13 AC 418 ms
77,804 KB
testcase_14 AC 295 ms
77,868 KB
testcase_15 AC 281 ms
78,092 KB
testcase_16 AC 1,011 ms
78,300 KB
testcase_17 AC 713 ms
78,324 KB
testcase_18 AC 1,669 ms
77,940 KB
testcase_19 AC 800 ms
77,904 KB
testcase_20 AC 797 ms
74,492 KB
testcase_21 AC 746 ms
74,108 KB
testcase_22 AC 783 ms
73,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from operator import itemgetter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18

N, B = map(int, input().split())
P = list(tuple(map(int, input().split())) for _ in range(N))
P.sort(key=itemgetter(1))
X, _, _ = zip(*P)
X = sorted(set(X))

ans = 0

for i in range(len(X)):
    for j in range(i, len(X)):
        l = 0
        r = 0
        cnt = 0
        score = 0
        while r < N:
            yr = P[r][1]
            while r < N and P[r][1] == yr:
                if X[i] <= P[r][0] <= X[j]:
                    cnt += 1
                    score += P[r][2]
                r += 1
            while score > B:
                yl = P[l][1]
                while l < N and P[l][1] == yl:
                    if X[i] <= P[l][0] <= X[j]:
                        cnt -= 1
                        score -= P[l][2]
                    l += 1
            ans = max(ans, cnt)

print(ans)
0