题库练习 Knights of a Polygonal Table
← 上一题 下一题 →

A11787 | Knights of a Polygonal Table

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $k$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.

Now each knight ponders: how many coins he can have if only he kills other knights?

You should answer this question for each knight.

输入格式

The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.

The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.

The third line contains $n$ integers $c_1, c_2 ,\ldots,c_n$ $(0 \le c_i \le 10^9)$ — the number of coins each knight has.

输出格式

Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights.

输入输出样例

输入 #1
4 2
4 5 9 7
1 2 11 33
输出 #1
1 3 46 36 
输入 #2
5 1
1 2 3 4 5
1 2 3 4 5
输出 #2
1 3 5 7 9 
输入 #3
1 0
2
3
输出 #3
3 
C++ 编辑器
输入
输出