結果

問題 No.1008 Bench Craftsman
ユーザー H3PO4H3PO4
提出日時 2021-08-22 10:09:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 157,248 KB
最終ジャッジ日時 2024-04-23 23:55:10
合計ジャッジ時間 7,397 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,608 KB
testcase_01 AC 39 ms
51,968 KB
testcase_02 AC 38 ms
52,480 KB
testcase_03 AC 43 ms
57,856 KB
testcase_04 AC 43 ms
58,112 KB
testcase_05 AC 326 ms
157,248 KB
testcase_06 AC 188 ms
151,056 KB
testcase_07 AC 38 ms
53,168 KB
testcase_08 AC 48 ms
64,640 KB
testcase_09 AC 185 ms
82,176 KB
testcase_10 AC 295 ms
154,556 KB
testcase_11 AC 292 ms
154,036 KB
testcase_12 AC 294 ms
154,264 KB
testcase_13 AC 290 ms
154,304 KB
testcase_14 AC 291 ms
154,424 KB
testcase_15 AC 105 ms
91,888 KB
testcase_16 AC 300 ms
153,968 KB
testcase_17 AC 103 ms
92,100 KB
testcase_18 AC 305 ms
153,700 KB
testcase_19 AC 288 ms
154,016 KB
testcase_20 AC 171 ms
125,612 KB
testcase_21 AC 165 ms
115,536 KB
testcase_22 AC 199 ms
101,264 KB
testcase_23 AC 251 ms
124,276 KB
testcase_24 AC 239 ms
112,588 KB
testcase_25 AC 187 ms
143,072 KB
testcase_26 AC 156 ms
126,428 KB
testcase_27 AC 176 ms
93,700 KB
testcase_28 AC 217 ms
133,800 KB
testcase_29 AC 264 ms
128,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline


def accumulate(X):
    Y = [0] * len(X)
    Y[0] = X[0]
    for i in range(1, len(X)):
        Y[i] = Y[i - 1] + X[i]
    return Y


def isOK(c):
    imos = [0] * (N + 2)
    for x, w in people:
        left = max(x - (w // c), 0)
        imos[left] += w - c * (x - left)
        imos[left + 1] += c - (w - c * (x - left))
        imos[x + 1] -= 2 * c
        right = min(x + (w // c), N - 1)
        imos[right + 1] += c - (w - c * (right - x))
        imos[right + 2] += w - c * (right - x)

    B = accumulate(accumulate(imos))
    for i in range(N):
        if B[i] >= A[i]:
            return False
    return True


def solve(N, A, people):
    # 耐久度0
    if min(A) > sum(w for _, w in people):
        return 0

    # 不可能
    direct = [0] * N
    for x, w in people:
        direct[x] += w
    for i in range(N):
        if direct[i] >= A[i]:
            return -1

    l, r = 0, 10 ** 9
    while r - l > 1:
        m = (r + l) // 2
        if isOK(m):
            r = m
        else:
            l = m
    return r


N, M = map(int, input().split())
A = tuple(map(int, input().split()))
people = []
for _ in range(M):
    x, w = map(int, input().split())
    x -= 1
    people.append((x, w))

print(solve(N, A, people))
0