結果

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

ソースコード

diff #

# coding: utf-8
# Your code here!
"""
a(x-p) + b (p <= x <= q) の2階階差をとり、imos配列に加える
"""
def kaisa2_of_tousa(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
    return

import sys
readline = sys.stdin.readline
read = sys.stdin.read

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)]
V = 0
for i in range(m):
    xw[i][0] -= 1
    V += xw[i][1]

if V < min(a):
    print(0)
    exit()

from itertools import accumulate
def check(c): #耐久値 x で耐えられるか?
    imos = [0]*(n)
    for x,w in xw:
        v = w//c
        l = max(0,x-v)
        kaisa2_of_tousa(c,w-c*(x-l),l,x-1,imos)
        kaisa2_of_tousa(-c,w,x,min(n-1,x+v),imos)

    imos = accumulate(imos)    
    imos = list(accumulate(imos))
    return all(im < ai for im,ai in zip(imos,a))    

ng = 0
ok = M = 10**5+9
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