結果

問題 No.1008 Bench Craftsman
ユーザー maspymaspy
提出日時 2020-03-06 22:24:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,333 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 171,092 KB
最終ジャッジ日時 2024-04-22 08:47:07
合計ジャッジ時間 6,493 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,788 KB
testcase_01 AC 39 ms
52,644 KB
testcase_02 AC 39 ms
53,684 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 260 ms
144,620 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 59 ms
68,564 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 169 ms
117,932 KB
testcase_21 AC 162 ms
110,660 KB
testcase_22 AC 164 ms
97,660 KB
testcase_23 AC 211 ms
119,824 KB
testcase_24 AC 190 ms
109,408 KB
testcase_25 AC 181 ms
125,532 KB
testcase_26 AC 165 ms
116,444 KB
testcase_27 AC 147 ms
94,148 KB
testcase_28 AC 193 ms
119,840 KB
testcase_29 AC 232 ms
141,944 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 test(c):
    if c == 0:
        return sum(w for x, w in XW) <= min(A)

    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 all(x <= a for a, x in zip(A, cost))


# %%
if any(A[x - 1] < w for x, w in XW):
    print(-1)
    exit()

left = -1
right = 10 * 5 + 10
while left + 1 < right:
    x = (left + right) // 2
    if test(x):
        right = x
    else:
        left = x
print(right)
0