結果

問題 No.1008 Bench Craftsman
ユーザー maspymaspy
提出日時 2020-03-06 22:33:50
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,334 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 180,472 KB
最終ジャッジ日時 2024-04-22 09:00:51
合計ジャッジ時間 9,044 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,096 KB
testcase_01 AC 38 ms
52,352 KB
testcase_02 RE -
testcase_03 AC 38 ms
52,864 KB
testcase_04 WA -
testcase_05 AC 393 ms
171,828 KB
testcase_06 AC 256 ms
162,368 KB
testcase_07 WA -
testcase_08 AC 63 ms
67,072 KB
testcase_09 AC 192 ms
100,992 KB
testcase_10 AC 346 ms
164,700 KB
testcase_11 AC 347 ms
162,008 KB
testcase_12 AC 357 ms
174,492 KB
testcase_13 AC 357 ms
178,076 KB
testcase_14 AC 352 ms
170,528 KB
testcase_15 RE -
testcase_16 AC 343 ms
167,544 KB
testcase_17 RE -
testcase_18 WA -
testcase_19 AC 351 ms
177,280 KB
testcase_20 AC 217 ms
126,056 KB
testcase_21 AC 197 ms
116,692 KB
testcase_22 AC 212 ms
99,568 KB
testcase_23 AC 292 ms
131,264 KB
testcase_24 AC 266 ms
120,048 KB
testcase_25 AC 249 ms
142,564 KB
testcase_26 AC 221 ms
130,820 KB
testcase_27 AC 183 ms
94,592 KB
testcase_28 AC 310 ms
132,816 KB
testcase_29 AC 335 ms
152,772 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))


# %%
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:
    raise
    print(-1)
else:
    print(right)
0