Codeforces Round 488 by NEAR (Div. 2)
B
Knights of a Polygonal Table
Codeforces
1400
原题
← AC →
翻译中…

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.

翻译中…

Input

翻译中…

The first line contains two integers n and k (1≤n≤105,0≤k≤min(n−1,10)) — the number of knights and the number k from the statement.

翻译中…

The second line contains n integers p1,p2,…,pn (1≤pi≤109) — powers of the knights. All pi are distinct.

翻译中…

The third line contains n integers c1,c2,…,cn (0≤ci≤109) — the number of coins each knight has.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

Consider the first example.

翻译中…
  • The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has.
  • The second knight can kill the first knight and add his coin to his own two.
  • The third knight is the strongest, but he can't kill more than k=2 other knights. It is optimal to kill the second and the fourth knights: 2+11+33=46.
  • The fourth knight should kill the first and the second knights: 33+1+2=36.
翻译中…

In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.

翻译中…

In the third example there is only one knight, so he can't kill anyone.

翻译中…

样例

Input #1
4 2
4 5 9 7
1 2 11 33
Output #1
1 3 46 36
InputCopy OutputCopy
Input #2
5 1
1 2 3 4 5
1 2 3 4 5
Output #2
1 3 5 7 9
InputCopy OutputCopy
Input #3
1 0
2
3
Output #3
3
InputCopy OutputCopy
题目信息
题号
994B
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。