結果
| 問題 | No.165 四角で囲え! |
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-21 15:26:22 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,899 ms / 5,000 ms |
| コード長 | 933 bytes |
| コンパイル時間 | 241 ms |
| コンパイル使用メモリ | 82,140 KB |
| 実行使用メモリ | 77,240 KB |
| 最終ジャッジ日時 | 2024-12-22 23:19:41 |
| 合計ジャッジ時間 | 29,889 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
#!/usr/bin/ python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
N, B = map(int, readline().split())
m = map(int, read().split())
X, Y, P = zip(*zip(m, m, m))
def compress(A):
x_to_i = {x: i for i, x in enumerate(sorted(set(A)))}
return tuple(x_to_i[x] for x in A)
X = compress(X)
Y = compress(Y)
H = max(X)
W = max(Y)
best_N = 0
for i, j in itertools.combinations(range(W + 2), 2):
Ns = [0] * (H + 2)
Ps = [0] * (H + 2)
INF = B + 10
Ps[-1] = INF
for x, y, p in zip(X, Y, P):
if i <= y < j:
Ns[x] += 1
Ps[x] += p
R = 0
S = 0
N = 0
for L in range(H + 1):
while R < L or S + Ps[R] <= B:
N += Ns[R]
S += Ps[R]
R += 1
if best_N < N:
best_N = N
S -= Ps[L]
N -= Ns[L]
print(best_N)
maspy