結果

問題 No.1008 Bench Craftsman
ユーザー maspymaspy
提出日時 2020-03-06 22:39:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 1,396 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 185,304 KB
最終ジャッジ日時 2024-04-22 09:46:48
合計ジャッジ時間 9,137 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,480 KB
testcase_01 AC 46 ms
52,224 KB
testcase_02 AC 42 ms
52,352 KB
testcase_03 AC 43 ms
52,736 KB
testcase_04 AC 43 ms
52,864 KB
testcase_05 AC 401 ms
174,280 KB
testcase_06 AC 280 ms
160,908 KB
testcase_07 AC 41 ms
52,224 KB
testcase_08 AC 64 ms
65,280 KB
testcase_09 AC 199 ms
100,608 KB
testcase_10 AC 364 ms
161,156 KB
testcase_11 AC 354 ms
157,940 KB
testcase_12 AC 376 ms
163,716 KB
testcase_13 AC 397 ms
171,780 KB
testcase_14 AC 361 ms
165,496 KB
testcase_15 AC 363 ms
174,944 KB
testcase_16 AC 356 ms
169,948 KB
testcase_17 AC 364 ms
174,172 KB
testcase_18 AC 429 ms
170,340 KB
testcase_19 AC 397 ms
185,304 KB
testcase_20 AC 273 ms
123,644 KB
testcase_21 AC 198 ms
118,248 KB
testcase_22 AC 212 ms
99,028 KB
testcase_23 AC 286 ms
123,324 KB
testcase_24 AC 268 ms
118,700 KB
testcase_25 AC 248 ms
136,848 KB
testcase_26 AC 214 ms
128,096 KB
testcase_27 AC 191 ms
94,848 KB
testcase_28 AC 271 ms
131,736 KB
testcase_29 AC 344 ms
153,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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


# %%
def calc_cost(N, c, XW):
    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
    B0 = list(itertools.accumulate(B0_d))[:-1]
    B1 = list(itertools.accumulate(B1_d))[:-1]
    cost = [a * i + b for i, (a, b) in enumerate(zip(B1, B0))]
    return cost


def test(c):
    if c == 0:
        return sum(w for x, w in XW) <= min(A)
    cost = calc_cost(N, c, XW)
    return all(x < a for a, x in zip(A, cost))


# %%
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