結果

問題 No.1008 Bench Craftsman
ユーザー titiatitia
提出日時 2020-05-29 15:21:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 844 ms / 2,000 ms
コード長 1,411 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 261,196 KB
最終ジャッジ日時 2024-04-23 04:20:11
合計ジャッジ時間 15,622 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,120 KB
testcase_01 AC 44 ms
52,736 KB
testcase_02 AC 41 ms
51,968 KB
testcase_03 AC 54 ms
64,000 KB
testcase_04 AC 53 ms
62,976 KB
testcase_05 AC 826 ms
260,712 KB
testcase_06 AC 481 ms
260,228 KB
testcase_07 AC 38 ms
52,748 KB
testcase_08 AC 95 ms
77,076 KB
testcase_09 AC 377 ms
86,012 KB
testcase_10 AC 825 ms
260,720 KB
testcase_11 AC 819 ms
260,772 KB
testcase_12 AC 822 ms
260,676 KB
testcase_13 AC 844 ms
260,920 KB
testcase_14 AC 801 ms
260,940 KB
testcase_15 AC 132 ms
90,360 KB
testcase_16 AC 820 ms
261,196 KB
testcase_17 AC 131 ms
90,432 KB
testcase_18 AC 814 ms
260,984 KB
testcase_19 AC 806 ms
260,524 KB
testcase_20 AC 448 ms
226,980 KB
testcase_21 AC 422 ms
192,288 KB
testcase_22 AC 429 ms
147,768 KB
testcase_23 AC 657 ms
200,304 KB
testcase_24 AC 561 ms
201,252 KB
testcase_25 AC 491 ms
231,788 KB
testcase_26 AC 409 ms
218,660 KB
testcase_27 AC 384 ms
115,072 KB
testcase_28 AC 565 ms
254,324 KB
testcase_29 AC 731 ms
235,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
A=list(map(int,input().split()))

PE=[tuple(map(int,input().split())) for i in range(M)]

P=[0]*(N+1)
for x,w in PE:
    P[x]+=w

for i in range(N):
    if A[i]<=P[i+1]:
        print(-1)
        sys.exit()

OK=1<<62
NG=-1

while OK-NG>1:
    mid=(OK+NG)//2
    
    P=[0]*(N+2)
    R=[0]*(N+2)
    L=[0]*(N+2)

    RR=[0]*(N+2)
    LL=[0]*(N+2)
    
    for x,w in PE:
        if mid!=0:
            h=w//mid
        else:
            h=10**9

        P[max(1,x-h)]+=w
        if x+h+1<N+2:
            P[x+h+1]-=w

        if h==0:
            continue

        R[x+1]-=mid
        if x+h+1<N+2:
            R[x+h+1]+=mid
        if x+h+1<N+2:
            RR[x+h+1]+=h*mid

        L[x-1]-=mid
        if x-h-1>=0:
            L[x-h-1]+=mid
        if x-h-1>=0:
            LL[x-h-1]+=h*mid

    #print(P,R,L,RR,LL)

    for i in range(1,N+2):
        P[i]+=P[i-1]
        R[i]+=R[i-1]

    for i in range(N,-1,-1):
        L[i]+=L[i+1]

    for i in range(N+2):
        R[i]+=RR[i]
        L[i]+=LL[i]

    for i in range(1,N+2):
        R[i]+=R[i-1]

    for i in range(N,-1,-1):
        L[i]+=L[i+1]

    #print(mid,P,R,L)
    #print([P[i]+R[i]+L[i] for i in range(1,N+1)])

    for i in range(1,N+1):
        if P[i]+R[i]+L[i]<A[i-1]:
            True
        else:
            NG=mid
            break
    else:
        OK=mid
print(OK)
0