import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
}
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
static int N = 500_100;
static long[] a = new long[N];
static int [] l = new int[N];
static int [] r = new int[N];
static long n,k;
public static class Pair implements Comparable<Pair>{
long val;
int idx;
Pair(long val,int idx){
this.val=val;
this.idx=idx;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
return Long.compare(this.val, o.val);
}
}
public static void main(String[] args) {
PriorityQueue<Pair> heap = new PriorityQueue<>();
Scanner scanner = new Scanner(System.in);
n = scanner.nextLong();
k = scanner.nextLong();
List<Pair> list = new LinkedList<>();
for (int i = 1; i <= n; i++) {
a[i]=scanner.nextLong();
heap.add(new Pair(a[i], i));
l[i]=i-1;
r[i]=i+1;
}
r[0]=1;
while(k>0&&!heap.isEmpty()) {
Pair p = heap.poll();
long val = p.val;
int pos = p.idx;
if(val!=a[pos]) {
continue;
}
k--;
if(l[pos]>=1) {
a[l[pos]]+=val;
heap.add(new Pair(a[l[pos]], l[pos]));//放进小跟堆 会一直排序
}
if(r[pos]<=n) {
a[r[pos]]+=val;
heap.add(new Pair(a[r[pos]], r[pos]));
}
//断开原来pos的值
r[l[pos]]=r[pos];
l[r[pos]]=l[pos];
}
for (int i = r[0]; i <= n; i=r[i]) {
System.out.print(a[i]+" ");
}
}}
0 回复
0 转发
0 喜欢
1 阅读



