import sys
import heapq
sys.setrecursionlimit(10000)
input=lambda:sys.stdin.readline().strip()
def del_func(x, v, l, r):
r[l[x]] = r[x]
l[r[x]] = l[x]
v[l[x]] += v[x]
v[r[x]] += v[x]
n, k = map(int, sys.stdin.readline().split())
v = [0] (n + 2)
l = [0] (n + 2)
r = [0] * (n + 2)
h = []
r[0] = 1
l[n + 1] = n
nums = [int(n) for n in sys.stdin.readline().split()]
for i in range(1, n + 1):
v[i] = nums[i - 1]#int(input())
l[i] = i - 1
r[i] = i + 1
heapq.heappush(h, (v[i], i))
while k > 0:
p = heapq.heappop(h)
if p[0] != v[p[1]]:
heapq.heappush(h, (v[p[1]], p[1]))
k += 1
else:
del_func(p[1], v, l, r)
k -= 1
head = r[0]
while head != n + 1:
sys.stdout.write(str(v[head]) + " ")
head = r[head]
import heapq
import time
from math import sqrt,gcd
sys.setrecursionlimit(10000)
input=lambda:sys.stdin.readline().strip()
def del_func(x, v, l, r):
r[l[x]] = r[x]
l[r[x]] = l[x]
v[l[x]] += v[x]
v[r[x]] += v[x]
n, k = map(int, sys.stdin.readline().split())
v = [0] (n + 2)
l = [0] (n + 2)
r = [0] * (n + 2)
h = []
r[0] = 1
l[n + 1] = n
nums = [int(n) for n in sys.stdin.readline().split()]
for i in range(1, n + 1):
v[i] = nums[i - 1]#int(input())
l[i] = i - 1
r[i] = i + 1
heapq.heappush(h, (v[i], i))
while k > 0:
p = heapq.heappop(h)
if p[0] != v[p[1]]:
heapq.heappush(h, (v[p[1]], p[1]))
k += 1
else:
del_func(p[1], v, l, r)
k -= 1
head = r[0]
while head != n + 1:
sys.stdout.write(str(v[head]) + " ")
head = r[head]
0 回复
0 转发
0 喜欢
1 阅读



