結果

問題 No.1008 Bench Craftsman
ユーザー maspymaspy
提出日時 2020-03-06 22:56:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 838 ms / 2,000 ms
コード長 1,321 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 55,076 KB
最終ジャッジ日時 2024-04-22 10:09:10
合計ジャッジ時間 23,671 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 538 ms
44,556 KB
testcase_01 AC 521 ms
44,164 KB
testcase_02 AC 526 ms
44,292 KB
testcase_03 AC 524 ms
44,548 KB
testcase_04 AC 521 ms
44,552 KB
testcase_05 AC 838 ms
54,480 KB
testcase_06 AC 601 ms
47,236 KB
testcase_07 AC 516 ms
44,548 KB
testcase_08 AC 531 ms
44,300 KB
testcase_09 AC 668 ms
50,828 KB
testcase_10 AC 762 ms
54,672 KB
testcase_11 AC 763 ms
55,076 KB
testcase_12 AC 772 ms
55,036 KB
testcase_13 AC 771 ms
54,676 KB
testcase_14 AC 769 ms
54,656 KB
testcase_15 AC 779 ms
54,792 KB
testcase_16 AC 771 ms
55,040 KB
testcase_17 AC 785 ms
54,548 KB
testcase_18 AC 789 ms
54,784 KB
testcase_19 AC 787 ms
54,660 KB
testcase_20 AC 593 ms
46,804 KB
testcase_21 AC 585 ms
46,024 KB
testcase_22 AC 657 ms
51,204 KB
testcase_23 AC 699 ms
52,780 KB
testcase_24 AC 697 ms
53,124 KB
testcase_25 AC 600 ms
48,576 KB
testcase_26 AC 576 ms
46,596 KB
testcase_27 AC 635 ms
49,296 KB
testcase_28 AC 650 ms
48,716 KB
testcase_29 AC 733 ms
52,560 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)
XW = np.array(read().split(), np.int64)
X = XW[::2] - 1
W = XW[1::2]


# %%
def calc_cost(N, c, X, W):
    B1_d = np.zeros(N + 1, np.int64)
    B0_d = np.zeros(N + 1, np.int64)
    L = X - (W + c - 1) // c + 1
    L = np.maximum(0, L)
    const_term = W - c * X
    np.add.at(B1_d, L, c)
    np.add.at(B0_d, L, const_term)
    np.add.at(B1_d, X+1, -c)
    np.add.at(B0_d, X + 1, -const_term)

    R = X + (W + c - 1) // c - 1
    R = np.minimum(R, N - 1)
    const_term = W + c * X
    np.add.at(B1_d, X + 1, -c)
    np.add.at(B0_d, X + 1, const_term)
    np.add.at(B1_d, R + 1, c)
    np.add.at(B0_d, R + 1, -const_term)
    B0 = np.cumsum(B0_d)[:-1]
    B1 = np.cumsum(B1_d)[:-1]
    return B0 + B1 * np.arange(N, dtype=np.int64)


def test(c):
    if c == 0:
        return W.sum() <= A.min()
    cost = calc_cost(N, c, X, W)
    return np.all(cost < A)


# %%
left = -1
right = 10 ** 5 + 10
while left + 1 < right:
    mid = (left + right) // 2
    if test(mid):
        right = mid
    else:
        left = mid

if right > 10 ** 5:
    print(-1)
else:
    print(right)
0