結果
問題 | No.1008 Bench Craftsman |
ユーザー | H3PO4 |
提出日時 | 2021-08-22 10:09:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 318 ms / 2,000 ms |
コード長 | 1,289 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 82,404 KB |
実行使用メモリ | 157,060 KB |
最終ジャッジ日時 | 2024-11-06 06:21:00 |
合計ジャッジ時間 | 8,189 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import sys input = sys.stdin.buffer.readline def accumulate(X): Y = [0] * len(X) Y[0] = X[0] for i in range(1, len(X)): Y[i] = Y[i - 1] + X[i] return Y def isOK(c): imos = [0] * (N + 2) for x, w in people: left = max(x - (w // c), 0) imos[left] += w - c * (x - left) imos[left + 1] += c - (w - c * (x - left)) imos[x + 1] -= 2 * c right = min(x + (w // c), N - 1) imos[right + 1] += c - (w - c * (right - x)) imos[right + 2] += w - c * (right - x) B = accumulate(accumulate(imos)) for i in range(N): if B[i] >= A[i]: return False return True def solve(N, A, people): # 耐久度0 if min(A) > sum(w for _, w in people): return 0 # 不可能 direct = [0] * N for x, w in people: direct[x] += w for i in range(N): if direct[i] >= A[i]: return -1 l, r = 0, 10 ** 9 while r - l > 1: m = (r + l) // 2 if isOK(m): r = m else: l = m return r N, M = map(int, input().split()) A = tuple(map(int, input().split())) people = [] for _ in range(M): x, w = map(int, input().split()) x -= 1 people.append((x, w)) print(solve(N, A, people))