結果

問題 No.1008 Bench Craftsman
ユーザー maspymaspy
提出日時 2020-03-06 22:14:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,276 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 65,852 KB
最終ジャッジ日時 2024-04-22 08:17:25
合計ジャッジ時間 45,661 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 522 ms
44,528 KB
testcase_01 AC 519 ms
44,404 KB
testcase_02 AC 516 ms
44,272 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 TLE -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 566 ms
44,400 KB
testcase_09 WA -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 WA -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 916 ms
49,280 KB
testcase_21 AC 985 ms
50,464 KB
testcase_22 AC 1,405 ms
60,408 KB
testcase_23 AC 1,633 ms
60,660 KB
testcase_24 AC 1,675 ms
61,928 KB
testcase_25 AC 743 ms
47,960 KB
testcase_26 AC 696 ms
46,568 KB
testcase_27 AC 1,282 ms
57,840 KB
testcase_28 AC 1,229 ms
53,804 KB
testcase_29 AC 1,782 ms
60,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

# %%
N, M = map(int, readline().split())
A = np.array(readline().split(), np.int64)
m = map(int, read().split())
XW = tuple(zip(m, m))


# %%
def test(c):
    if c == 0:
        return sum(w for x, w in XW) <= A.min()

    B1_d = [0] * (N + 1)
    B0_d = [0] * (N + 1)

    for x, w in XW:
        x -= 1
        L = x - (w + c - 1) // c + 1
        if L < 0:
            L = 0
        const_term = w - c * x
        B1_d[L] += c
        B0_d[L] += const_term
        B1_d[x + 1] -= c
        B0_d[x + 1] -= const_term
        R = x + (w + c - 1) // c - 1
        const_term = w + c * x
        if R >= N:
            R = N - 1
        B1_d[x + 1] -= c
        B0_d[x + 1] += const_term
        B1_d[R + 1] += c
        B0_d[R + 1] -= const_term

    B1 = np.cumsum(B1_d)[:-1]
    B0 = np.cumsum(B0_d)[:-1]
    cost = B1 * np.arange(N, dtype=np.int64) + B0
    return np.all(cost <= A)


# %%
if any(A[x - 1] < w for x, w in XW):
    print(-1)
    exit()

left = -1
right = 10 * 5 + 10
while left + 1 < right:
    x = (left + right) // 2
    if test(x):
        right = x
    else:
        left = x
print(right)
0