結果

問題 No.165 四角で囲え!
ユーザー rlangevinrlangevin
提出日時 2023-07-27 12:11:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 959 ms / 5,000 ms
コード長 1,080 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 77,648 KB
最終ジャッジ日時 2024-04-15 00:24:08
合計ジャッジ時間 10,509 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 522 ms
77,188 KB
testcase_01 AC 41 ms
55,068 KB
testcase_02 AC 41 ms
55,968 KB
testcase_03 AC 40 ms
54,620 KB
testcase_04 AC 42 ms
56,236 KB
testcase_05 AC 668 ms
77,236 KB
testcase_06 AC 244 ms
76,920 KB
testcase_07 AC 41 ms
54,244 KB
testcase_08 AC 40 ms
55,544 KB
testcase_09 AC 41 ms
54,816 KB
testcase_10 AC 41 ms
54,708 KB
testcase_11 AC 487 ms
77,564 KB
testcase_12 AC 336 ms
77,648 KB
testcase_13 AC 268 ms
77,180 KB
testcase_14 AC 295 ms
77,356 KB
testcase_15 AC 272 ms
77,128 KB
testcase_16 AC 959 ms
77,452 KB
testcase_17 AC 746 ms
77,432 KB
testcase_18 AC 831 ms
77,132 KB
testcase_19 AC 832 ms
77,324 KB
testcase_20 AC 748 ms
77,020 KB
testcase_21 AC 746 ms
77,032 KB
testcase_22 AC 746 ms
77,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, B = map(int, input().split())
X, Y, P = [0] * N, [0] * N, [0] * N
XS = set()
DD = []
for i in range(N):
    X[i], Y[i], P[i] = map(int, input().split())
    XS.add(X[i])
    DD.append((Y[i], X[i], P[i]))

DD.sort()

from collections import *
def solve(L):
    inf = 10 ** 18
    K = len(L)
    L.append((inf, inf))
    Q = deque()
    now = -1
    val = 0
    temp = 0
    for i in range(K):
        Q.append(L[i])
        val += L[i][1]
        if L[i][0] == L[i + 1][0]:
            continue
        while Q:
            if val > B or Q[0][0] == now:
                now = Q[0][0]
                val -= Q[0][1]
                Q.popleft()
            else:
                break
        temp = max(temp, len(Q))
    return temp


XL = sorted(list(XS))
M = len(XL)
ans = 0
for i in range(M):
    for j in range(i, M):
        left = XL[i]
        right = XL[j]
        D = []
        for k in range(N):
            if left <= DD[k][1] <= right:
                D.append((DD[k][0], DD[k][2]))
        ans = max(ans, solve(D))

print(ans)
0