Problem p02750 (python)

Fixed submission:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 解説

N, T = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

# 移動時間を考えなくて良いようにする
A += 1
B += 1
T += 1

# 使う店を決めたとき、(a - 1) / b の大きい順に使うのが最適
I = np.argsort((A - 1) / B)[::-1]
A = A[I]
B = B[I]

idx_zero = np.searchsorted((A == 1).astype(int), 1, side='left')
A1 = A[:idx_zero]
B1 = B[:idx_zero]
B2 = np.msort(B[idx_zero:])

MAX_COUNT = (10 ** 9).bit_length() + 2
# dp[i][x]: i まで見て、x こ使うときの t の最小値
dp = np.full((idx_zero + 1, MAX_COUNT), T + 1, dtype=int)
dp[:, 0] = 1
for x in range(MAX_COUNT - 1):
    next_col = dp[:-1, x] * A1 + B1
    np.minimum(next_col, T + 1, out=next_col)
    np.minimum.accumulate(next_col, out=next_col)
    dp[1:, x + 1] = next_col

# idx_zero 以降で、B を小さい順に使えるだけ使う
cum = B2.cumsum()
counts = np.searchsorted(cum, T - dp[idx_zero], side='right')
ans = counts + np.arange(dp.shape[1])
print(ans[dp[idx_zero] <= T].max())

Buggy submission (verdict: Runtime Error):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 解説

N, T = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

# 移動時間を考えなくて良いようにする
A += 1
B += 1
T += 1

# 使う店を決めたとき、(a - 1) / b の大きい順に使うのが最適
I = np.argsort((A - 1) / B)[::-1]
A = A[I]
B = B[I]

idx_zero = np.searchsorted((A == 1).astype(int), 1, side='left')
MAX_COUNT = 1 << ((2 * 10 ** 5).bit_length() + 2)
# dp[i][x]: i まで見て、x こ使うときの t の最小値
dp = np.full((idx_zero + 1, MAX_COUNT), IINF, dtype=int)
dp[0, 0] = 1
for i in range(len(dp) - 1):
    dp[i + 1, :] = np.minimum(dp[i + 1, :], dp[i, :])
    dp[i + 1, 1:] = np.minimum(dp[i + 1, 1:], dp[i, :-1] * A[i] + B[i])
    np.minimum(dp[i + 1], T + 1, out=dp[i + 1])

#: :type: list of int
B_A0 = np.msort(B[idx_zero:]).tolist()
ans = 0
# idx_zero 以降で、B を小さい順に使えるだけ使う
for cnt, t in enumerate(dp[idx_zero].tolist()):
    if t > T:
        break
    i = 0
    while i < len(B_A0) and t + B_A0[i] <= T:
        t += B_A0[i]
        i += 1
        cnt += 1
    ans = max(ans, cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 解説

N, T = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

# 移動時間を考えなくて良いようにする
A += 1
B += 1
T += 1

# 使う店を決めたとき、(a - 1) / b の大きい順に使うのが最適
I = np.argsort((A - 1) / B)[::-1]
A = A[I]
B = B[I]

idx_zero = np.searchsorted((A == 1).astype(int), 1, side='left')
MAX_COUNT = 1 << ((2 * 10 ** 5).bit_length() + 2)
# dp[i][x]: i まで見て、x こ使うときの t の最小値
dp = np.full((idx_zero + 1, MAX_COUNT), IINF, dtype=int)
dp[0, 0] = 1
for i in range(len(dp) - 1):
    dp[i + 1, :] = np.minimum(dp[i + 1, :], dp[i, :])
    dp[i + 1, 1:] = np.minimum(dp[i + 1, 1:], dp[i, :-1] * A[i] + B[i])

#: :type: list of int
B_A0 = np.msort(B[idx_zero:]).tolist()
ans = 0
# idx_zero 以降で、B を小さい順に使えるだけ使う
for cnt, t in enumerate(dp[idx_zero].tolist()):
    if t > T:
        break
    i = 0
    while i < len(B_A0) and t + B_A0[i] <= T:
        t += B_A0[i]
        i += 1
        cnt += 1
    ans = max(ans, cnt)
print(ans)