結果

問題 No.1008 Bench Craftsman
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-19 15:50:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,459 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,676 KB
実行使用メモリ 194,772 KB
最終ジャッジ日時 2023-10-21 09:17:42
合計ジャッジ時間 13,740 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,460 KB
testcase_01 AC 41 ms
53,396 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 40 ms
53,460 KB
testcase_04 WA -
testcase_05 AC 632 ms
184,276 KB
testcase_06 AC 386 ms
172,272 KB
testcase_07 WA -
testcase_08 AC 54 ms
72,360 KB
testcase_09 WA -
testcase_10 AC 568 ms
186,188 KB
testcase_11 AC 559 ms
184,104 KB
testcase_12 AC 573 ms
186,412 KB
testcase_13 AC 560 ms
193,628 KB
testcase_14 AC 560 ms
185,920 KB
testcase_15 AC 534 ms
185,092 KB
testcase_16 AC 555 ms
185,548 KB
testcase_17 AC 523 ms
183,700 KB
testcase_18 WA -
testcase_19 AC 543 ms
194,772 KB
testcase_20 AC 304 ms
139,012 KB
testcase_21 AC 286 ms
123,788 KB
testcase_22 AC 318 ms
108,804 KB
testcase_23 AC 425 ms
145,384 KB
testcase_24 AC 387 ms
133,660 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 249 ms
94,308 KB
testcase_28 AC 348 ms
143,808 KB
testcase_29 AC 476 ms
165,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
A = tuple(map(int, input().split()))
XW = tuple(tuple(map(int, input().split())) for _ in range(M))
X, W = zip(*XW)
wsum = sum(W)
wmax = max(W)
if all(a >= wsum for a in A):
    print(0)
    exit()


def C(k):
    dpR = [0] * N
    dpL = [0] * N
    for x, w in XW:
        x -= 1
        d = (w + k - 1) // k
        if x + 1 < N:
            dpR[x + 1] -= k
            if x + d < N:
                dpR[x + d] += k
        if N - 1 - (x - 1) < N:
            dpL[N - 1 - (x - 1)] -= k
            if N - 1 - (x - d) < N:
                dpL[N - 1 - (x - d)] += k
    dpR = list(accumulate(dpR))
    dpL = list(accumulate(dpL))
    for x, w in XW:
        x -= 1
        d = (w + k - 1) // k
        dpR[x] += w
        dpL[N - 1 - x] += w
        if x + d < N:
            dpR[x + d] -= w
            dpR[x + d] += k * (d - 1)
        if N - 1 - (x - d) < N:
            dpL[N - 1 - (x - d)] -= w
            dpL[N - 1 - (x - d)] += k * (d - 1)
    dpR = list(accumulate(dpR))
    dpL = list(accumulate(dpL))
    dpL.reverse()
    B = [l + r for l, r in zip(dpL, dpR)]
    for x, w in XW:
        B[x - 1] -= w
    return all(a >= b for a, b in zip(A, B))


l = 1
r = wmax + 5
while r - l > 1:
    m = (r + l) // 2
    if C(m):
        r = m
    else:
        l = m

if r >= wmax:
    print(-1)
else:
    print(r)
0