結果

問題 No.1008 Bench Craftsman
ユーザー convexineqconvexineq
提出日時 2020-03-07 01:24:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 128,232 KB
最終ジャッジ日時 2023-08-04 14:03:04
合計ジャッジ時間 9,643 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,496 KB
testcase_01 AC 69 ms
71,420 KB
testcase_02 AC 67 ms
71,344 KB
testcase_03 AC 70 ms
71,628 KB
testcase_04 AC 69 ms
71,204 KB
testcase_05 AC 379 ms
117,764 KB
testcase_06 AC 201 ms
113,904 KB
testcase_07 AC 69 ms
71,412 KB
testcase_08 AC 87 ms
78,556 KB
testcase_09 AC 280 ms
86,948 KB
testcase_10 AC 334 ms
118,812 KB
testcase_11 AC 344 ms
120,588 KB
testcase_12 AC 337 ms
119,040 KB
testcase_13 AC 336 ms
122,424 KB
testcase_14 AC 327 ms
123,692 KB
testcase_15 AC 307 ms
128,232 KB
testcase_16 AC 318 ms
122,224 KB
testcase_17 AC 303 ms
124,908 KB
testcase_18 AC 350 ms
121,184 KB
testcase_19 AC 329 ms
123,008 KB
testcase_20 AC 239 ms
101,832 KB
testcase_21 AC 224 ms
97,184 KB
testcase_22 AC 260 ms
93,404 KB
testcase_23 AC 314 ms
106,168 KB
testcase_24 AC 300 ms
102,180 KB
testcase_25 AC 222 ms
108,560 KB
testcase_26 AC 202 ms
101,392 KB
testcase_27 AC 239 ms
88,368 KB
testcase_28 AC 272 ms
105,076 KB
testcase_29 AC 316 ms
111,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(a,b,p,q,imos):
    if p > q: return
    imos[p] += b
    if p+1 < n: imos[p+1] += a-b
    y = a*(q-p)+b
    if q+1 < n: imos[q+1] += -y-a
    if q+2 < n: imos[q+2] += y

import sys
readline = sys.stdin.readline

n,m = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]
xw = [[int(i) for i in readline().split()] for _ in range(m)]

from itertools import accumulate as acc
def check(c):
    imos = [0]*(n)
    for x,w in xw:
        x -= 1
        v = w//c
        l = max(0,x-v)
        f(c,w-c*(x-l),l,x-1,imos)
        f(-c,w,x,min(n-1,x+v),imos)
    res = list(acc(acc(imos)))
    return all(ri < ai for ri,ai in zip(res,a))    

ng = V = 0
ok = M = 2**17
if sum(r[1] for r in xw) < min(a): ok = 0

while ok-ng > 1:
    mid = (ok+ng)//2
    if check(mid): ok = mid
    else: ng = mid

if ok < M: print(ok)
else: print(-1)

0