結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-22 09:31:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,396 bytes |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 82,496 KB |
| 実行使用メモリ | 314,288 KB |
| 最終ジャッジ日時 | 2024-11-06 05:39:43 |
| 合計ジャッジ時間 | 20,041 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 2 TLE * 11 |
ソースコード
import sys
input = sys.stdin.buffer.readline
def isOK(c):
queries = [[] for _ in range(N + 1)]
for x, w in people:
left = max(x - (w // c), 0)
queries[left].append((1, w - c * (x - left)))
queries[x].append((2,))
right = min(x + (w // c), N)
queries[right].append((3, w - c * (right - x)))
positive = 0
cur = 0
for i in range(N):
cur += positive * c
for q in queries[i]:
if q[0] == 1:
positive += 1
cur += q[1]
elif q[0] == 2:
positive -= 2
else:
# assert q[0] == 3
positive += 1
cur -= q[1]
if cur >= A[i]:
return False
return True
def solve(N, M, 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, M, A, people))