結果

問題 No.1008 Bench Craftsman
ユーザー tamatotamato
提出日時 2020-03-06 22:42:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,594 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 149,000 KB
最終ジャッジ日時 2024-04-22 09:54:32
合計ジャッジ時間 7,639 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,224 KB
testcase_01 AC 38 ms
51,968 KB
testcase_02 AC 38 ms
52,224 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 39 ms
52,096 KB
testcase_08 AC 47 ms
64,128 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 191 ms
126,244 KB
testcase_26 AC 171 ms
120,128 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    weight = [0] * N
    for _ in range(M):
        x, w = map(int, input().split())
        weight[x-1] = w

    for i in range(N):
        if A[i] <= weight[i]:
            print(-1)
            exit()

    if sum(weight) < min(A):
        print(0)
        exit()

    ok = 10**9
    ng = 0
    mid = (ok+ng)//2
    while ok - ng > 1:
        B = [0] * N
        imos1 = [0] * N
        imos2 = [0] * N
        for x, w in enumerate(weight):
            if w:
                L, mod = divmod(w, mid)
                imos1[max(0, x-L)] += mod
                if x+L+1 < N:
                    imos1[x+L+1] -= mod
                if L:
                    if x-L+1 >= 0:
                        imos2[x-L+1] += 1
                    else:
                        imos2[0] += 1
                        imos1[0] += L-x-1
                    if x + 1 < N:
                        imos2[x + 1] -= 2
                    if x + L < N:
                        imos2[x + L] += 1
        for i in range(1, N):
            imos2[i] += imos2[i-1]
        B[0] = imos1[0] + imos2[0] * mid
        for i in range(1, N-1):
            B[i] = B[i-1] + imos1[i] + imos2[i] * mid
        flg = 1
        for a, b in zip(A, B):
            if b >= a:
                flg = 0
                break
        if flg:
            ok = mid
        else:
            ng = mid
        mid = (ok+ng)//2
        #print(ok, ng, mid)
    print(ok)


if __name__ == '__main__':
    main()
0