結果

問題 No.1008 Bench Craftsman
ユーザー titiatitia
提出日時 2020-05-29 15:17:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,452 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 261,244 KB
最終ジャッジ日時 2024-04-23 04:14:22
合計ジャッジ時間 13,362 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,120 KB
testcase_01 AC 35 ms
53,120 KB
testcase_02 AC 33 ms
52,096 KB
testcase_03 AC 52 ms
64,000 KB
testcase_04 WA -
testcase_05 AC 801 ms
260,632 KB
testcase_06 AC 445 ms
259,636 KB
testcase_07 WA -
testcase_08 AC 86 ms
77,056 KB
testcase_09 AC 317 ms
86,256 KB
testcase_10 AC 671 ms
261,044 KB
testcase_11 AC 667 ms
260,600 KB
testcase_12 AC 694 ms
260,716 KB
testcase_13 AC 679 ms
260,652 KB
testcase_14 AC 662 ms
260,516 KB
testcase_15 AC 113 ms
90,364 KB
testcase_16 AC 661 ms
260,724 KB
testcase_17 AC 103 ms
90,368 KB
testcase_18 WA -
testcase_19 AC 648 ms
261,244 KB
testcase_20 AC 392 ms
227,160 KB
testcase_21 AC 346 ms
188,680 KB
testcase_22 AC 362 ms
147,328 KB
testcase_23 AC 520 ms
200,748 KB
testcase_24 AC 466 ms
201,760 KB
testcase_25 AC 409 ms
231,964 KB
testcase_26 AC 342 ms
217,972 KB
testcase_27 AC 325 ms
115,452 KB
testcase_28 AC 474 ms
254,252 KB
testcase_29 AC 581 ms
235,300 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