結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
tamato
|
| 提出日時 | 2020-03-06 23:30:57 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,693 bytes |
| コンパイル時間 | 162 ms |
| コンパイル使用メモリ | 82,204 KB |
| 実行使用メモリ | 153,372 KB |
| 最終ジャッジ日時 | 2024-10-14 09:56:09 |
| 合計ジャッジ時間 | 8,716 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 2 |
ソースコード
def main():
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
weight = []
weight_sum = 0
for _ in range(M):
x, w = map(int, input().split())
x -= 1
weight.append((x, w))
if A[x] <= w:
print(-1)
exit()
weight_sum += w
if 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()
tamato