結果

問題 No.1008 Bench Craftsman
ユーザー H3PO4H3PO4
提出日時 2021-08-22 09:31:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,396 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 313,912 KB
最終ジャッジ日時 2024-04-23 23:18:49
合計ジャッジ時間 29,196 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,168 KB
testcase_01 AC 36 ms
52,952 KB
testcase_02 AC 33 ms
52,960 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 TLE -
testcase_06 AC 262 ms
134,356 KB
testcase_07 AC 37 ms
54,120 KB
testcase_08 AC 45 ms
66,180 KB
testcase_09 AC 569 ms
258,136 KB
testcase_10 AC 1,839 ms
298,624 KB
testcase_11 WA -
testcase_12 TLE -
testcase_13 AC 1,894 ms
313,912 KB
testcase_14 WA -
testcase_15 AC 95 ms
91,792 KB
testcase_16 WA -
testcase_17 AC 96 ms
92,144 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 481 ms
151,732 KB
testcase_21 AC 548 ms
153,924 KB
testcase_22 AC 1,087 ms
252,828 KB
testcase_23 AC 1,488 ms
298,628 KB
testcase_24 AC 1,443 ms
301,536 KB
testcase_25 AC 343 ms
127,060 KB
testcase_26 AC 301 ms
111,080 KB
testcase_27 AC 790 ms
185,804 KB
testcase_28 AC 864 ms
240,660 KB
testcase_29 AC 1,585 ms
296,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline


def isOK(c):
    queries = [[] for _ in range(N + 1)]
    for x, w in people:
        left = max(x - (w // c), 0)
        queries[left].append((1, w - c * (x - left)))
        queries[x].append((2,))
        right = min(x + (w // c), N)
        queries[right].append((3, w - c * (right - x)))

    positive = 0
    cur = 0
    for i in range(N):
        cur += positive * c
        for q in queries[i]:
            if q[0] == 1:
                positive += 1
                cur += q[1]
            elif q[0] == 2:
                positive -= 2
            else:
                # assert q[0] == 3
                positive += 1
                cur -= q[1]

        if cur >= A[i]:
            return False
    return True


def solve(N, M, 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, M, A, people))
0