結果

問題 No.1008 Bench Craftsman
ユーザー chielochielo
提出日時 2020-03-06 23:10:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,096 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 328,672 KB
最終ジャッジ日時 2024-04-22 10:25:31
合計ジャッジ時間 4,444 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
63,360 KB
testcase_01 AC 50 ms
58,236 KB
testcase_02 AC 44 ms
52,480 KB
testcase_03 AC 62 ms
62,208 KB
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
a = list(map(int, input().split()))
w = [0] * n
for i in range(m):
    u, v = map(int, input().split())
    w[u - 1] += v

def ceildiv(a, b):
    return -(-a // b)

def check(c):
    if c <= 0:
        return sum(w) <= min(a)
    pt = []
    for j in range(n):
        u = (w[j] + c * j) // c
        if u >= j:
            pt.append((j + 1, -c, w[j] + c * j))
            pt.append((u + 1, c, -(w[j] + c * j)))
        u = ceildiv(c * j - w[j], c)
        if u <= j:
            pt.append((u, c, w[j] - c * j))
            pt.append((j, -c, -(w[j] - c * j)))
        pt.append((j, 0, w[j]))
        pt.append((j + 1, 0, -w[j]))
    pt.sort()
    u, v = 0, 0
    cur = 0
    for i in range(n):
        while cur < len(pt) and pt[cur][0] <= i:
            u += pt[cur][1]
            v += pt[cur][2]
            cur += 1
        if u * i + v > a[i]:
            return False
    return True

l, r = -1, 10 ** 18
while r - l > 1:
    mid = (l + r) // 2
    if check(mid):
        r = mid
    else:
        l = mid
if r >= 10 ** 18:
    print(-1)
    exit()
print(r)
0