結果

問題 No.1008 Bench Craftsman
ユーザー maspymaspy
提出日時 2020-03-06 22:29:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,324 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 82,188 KB
実行使用メモリ 179,576 KB
最終ジャッジ日時 2024-04-22 08:55:22
合計ジャッジ時間 9,411 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 41 ms
52,608 KB
testcase_02 AC 40 ms
52,096 KB
testcase_03 AC 40 ms
52,096 KB
testcase_04 WA -
testcase_05 AC 408 ms
172,004 KB
testcase_06 AC 262 ms
162,488 KB
testcase_07 WA -
testcase_08 AC 65 ms
67,328 KB
testcase_09 AC 202 ms
101,344 KB
testcase_10 AC 363 ms
164,640 KB
testcase_11 AC 365 ms
161,508 KB
testcase_12 AC 377 ms
174,552 KB
testcase_13 AC 374 ms
178,260 KB
testcase_14 AC 367 ms
170,840 KB
testcase_15 AC 360 ms
179,576 KB
testcase_16 AC 355 ms
168,112 KB
testcase_17 AC 361 ms
176,760 KB
testcase_18 WA -
testcase_19 AC 378 ms
177,276 KB
testcase_20 AC 223 ms
125,800 KB
testcase_21 AC 204 ms
116,564 KB
testcase_22 AC 219 ms
99,172 KB
testcase_23 AC 304 ms
131,260 KB
testcase_24 AC 277 ms
119,992 KB
testcase_25 AC 260 ms
142,780 KB
testcase_26 AC 231 ms
131,480 KB
testcase_27 AC 191 ms
94,848 KB
testcase_28 AC 282 ms
133,460 KB
testcase_29 AC 345 ms
152,892 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:
    print(-1)
else:
    print(right)
0