結果

問題 No.1008 Bench Craftsman
ユーザー convexineqconvexineq
提出日時 2020-03-06 23:15:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,637 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 141,560 KB
最終ジャッジ日時 2024-04-22 10:28:26
合計ジャッジ時間 10,543 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,264 KB
testcase_01 AC 39 ms
52,956 KB
testcase_02 AC 40 ms
52,208 KB
testcase_03 AC 41 ms
52,884 KB
testcase_04 AC 41 ms
53,404 KB
testcase_05 WA -
testcase_06 AC 264 ms
129,220 KB
testcase_07 AC 41 ms
53,016 KB
testcase_08 AC 58 ms
74,528 KB
testcase_09 AC 294 ms
85,684 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 382 ms
140,164 KB
testcase_16 WA -
testcase_17 AC 394 ms
141,560 KB
testcase_18 AC 449 ms
135,796 KB
testcase_19 AC 439 ms
138,640 KB
testcase_20 AC 281 ms
108,200 KB
testcase_21 AC 270 ms
104,904 KB
testcase_22 AC 313 ms
96,768 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 278 ms
119,104 KB
testcase_26 AC 235 ms
110,952 KB
testcase_27 AC 276 ms
89,476 KB
testcase_28 AC 343 ms
109,844 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!

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)
    res = [0]*(n)
    for x,w in xw:
        res[x] += w
        v = w//c

        l = max(0,x-v)
        r = x-1
        #print(l,r)
        if l < r:
            X = w-(x-l)*c
            y = w-c
            imos[l] += X
            imos[l+1] += c-X
            if r+1 < n:
                imos[r+1] += -y-c
            if r+2 < n:
                imos[r+2] += y
        elif l==r:
            res[r] += w-c
        
        r = min(n-1,x+v)
        l = x+1
        #print(l,r)
        if l < r:
            X = w-c
            y = w-c+(r-x)
            imos[l] += X
            imos[l+1] += -c-X
            if r+1 < n:
                imos[r+1] += -y+c
            if r+2 < n:
                imos[r+1] += y
        elif l==r:
            res[r] += w-c
        
        #print(x,w,c)
        #print(imos)
        #imos = [0]*n
    imos = accumulate(imos)    
    imos = list(accumulate(imos))
    #print(imos,res,a)
    return all(imos[i]+res[i] < a[i] for i in range(n))    


#print(check(2))

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