結果

問題 No.1008 Bench Craftsman
ユーザー convexineq
提出日時 2020-03-07 01:24:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 124,420 KB
最終ジャッジ日時 2024-10-14 11:01:24
合計ジャッジ時間 8,098 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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