結果

問題 No.1008 Bench Craftsman
ユーザー tamatotamato
提出日時 2020-03-06 23:46:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 394 ms / 2,000 ms
コード長 1,743 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 148,876 KB
最終ジャッジ日時 2024-04-22 10:45:33
合計ジャッジ時間 8,287 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,096 KB
testcase_01 AC 41 ms
52,096 KB
testcase_02 AC 38 ms
52,224 KB
testcase_03 AC 39 ms
52,480 KB
testcase_04 AC 40 ms
52,992 KB
testcase_05 AC 388 ms
122,492 KB
testcase_06 AC 188 ms
148,876 KB
testcase_07 AC 38 ms
52,480 KB
testcase_08 AC 48 ms
65,792 KB
testcase_09 AC 231 ms
81,408 KB
testcase_10 AC 394 ms
116,828 KB
testcase_11 AC 392 ms
116,896 KB
testcase_12 AC 393 ms
116,828 KB
testcase_13 AC 385 ms
117,024 KB
testcase_14 AC 382 ms
116,828 KB
testcase_15 AC 106 ms
90,496 KB
testcase_16 AC 391 ms
117,468 KB
testcase_17 AC 105 ms
90,752 KB
testcase_18 AC 382 ms
116,836 KB
testcase_19 AC 391 ms
116,828 KB
testcase_20 AC 185 ms
110,236 KB
testcase_21 AC 194 ms
101,040 KB
testcase_22 AC 229 ms
91,400 KB
testcase_23 AC 312 ms
106,464 KB
testcase_24 AC 295 ms
99,704 KB
testcase_25 AC 191 ms
135,624 KB
testcase_26 AC 163 ms
122,536 KB
testcase_27 AC 198 ms
86,884 KB
testcase_28 AC 259 ms
106,512 KB
testcase_29 AC 334 ms
114,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

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

    ok = 10**9
    ng = 0
    mid = (ok+ng)//2
    while ok - ng > 1:
        #mid = 3
        B = [0] * N
        imos1 = [0] * N
        imos2 = [0] * N
        for x, w in 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)*mid
                    if x + 1 < N:
                        imos2[x + 1] -= 2
                    if x + L+1 < N:
                        imos2[x + L+1] += 1
        #print(mid, imos1, imos2)
        for i in range(1, N):
            imos2[i] += imos2[i-1]
        B[0] = imos1[0] + imos2[0] * mid
        for i in range(1, N):
            B[i] = B[i-1] + imos1[i] + imos2[i] * mid
        #print(mid, B, imos1, imos2)
        #exit()
        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)


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