E. Hoofball
-iknoom1107
λ¬Έμ μ€λͺ
μμ€μ½λ
n = int(input())
x = [-1e9] + sorted(map(int, input().split())) + [1e9]
vst = [False] * (n + 1)
ans = 0
while True:
tmp = []
for i in range(1,n+1):
if vst[i]: continue
p = q = i
while q <= n and x[q] - x[q - 1] > x[q + 1] - x[q] and not vst[q + 1]:
q += 1
while 0 < p and x[p] - x[p - 1] <= x[p + 1] - x[p] and not vst[q - 1]:
p -= 1
tmp.append((i - p, p, i))
tmp.append((q - i, i, q))
if not tmp: break
tmp.sort()
_, l, r = tmp[-1]
for i in range(l, r+1):
vst[i - 1] = True
ans += 1
print(ans)Last updated