結果

問題 No.1008 Bench Craftsman
ユーザー convexineqconvexineq
提出日時 2020-03-07 01:24:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 124,484 KB
最終ジャッジ日時 2024-04-22 11:40:46
合計ジャッジ時間 8,706 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,480 KB
testcase_01 AC 41 ms
51,968 KB
testcase_02 AC 41 ms
52,480 KB
testcase_03 AC 42 ms
52,608 KB
testcase_04 AC 42 ms
52,992 KB
testcase_05 AC 351 ms
116,536 KB
testcase_06 AC 181 ms
110,856 KB
testcase_07 AC 39 ms
52,352 KB
testcase_08 AC 57 ms
72,976 KB
testcase_09 AC 273 ms
85,632 KB
testcase_10 AC 321 ms
118,200 KB
testcase_11 AC 334 ms
116,796 KB
testcase_12 AC 331 ms
118,280 KB
testcase_13 AC 326 ms
119,608 KB
testcase_14 AC 317 ms
124,484 KB
testcase_15 AC 293 ms
123,904 KB
testcase_16 AC 314 ms
122,692 KB
testcase_17 AC 290 ms
122,324 KB
testcase_18 AC 339 ms
117,436 KB
testcase_19 AC 326 ms
123,016 KB
testcase_20 AC 221 ms
99,816 KB
testcase_21 AC 208 ms
97,576 KB
testcase_22 AC 248 ms
92,184 KB
testcase_23 AC 304 ms
103,652 KB
testcase_24 AC 284 ms
101,560 KB
testcase_25 AC 202 ms
105,264 KB
testcase_26 AC 188 ms
101,244 KB
testcase_27 AC 225 ms
87,152 KB
testcase_28 AC 262 ms
103,908 KB
testcase_29 AC 320 ms
112,916 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