CF994B.Knights of a Polygonal Table
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
与“圆桌骑士”不同,“多边形桌骑士”丧失了贵族风范,乐于相互残杀。但每位骑士都拥有一定的武力值,而一名骑士仅当其武力值严格大于另一名骑士时,才能将其杀死。然而,即便如此,这名骑士仍会因良知而备受煎熬,因此他最多只能杀死 k 名其他骑士。此外,每位骑士还拥有一些金币。在杀死一名骑士后,施害者可以拾取受害者所拥有的全部金币。
现在,每位骑士都在思考:若仅由他自己发动杀戮,他最多能获得多少枚金币?
你需要对每位骑士回答这一问题。
输入格式
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.
第一行包含两个整数 n 和 k (1≤n≤105,0≤k≤min(n−1,10)) —— 分别表示骑士的数量以及题目描述中的参数 k。
第二行包含 n 个整数 p1,p2,…,pn (1≤pi≤109) —— 表示各位骑士的力量值。所有 pi 互不相同。
第三行包含 n 个整数 c1,c2,…,cn (0≤ci≤109) —— 表示每位骑士所拥有的金币数量。
输出格式
Print n integers — the maximum number of coins each knight can have it only he kills other knights.
输出 n 个整数——即每位骑士仅通过击杀其他骑士所能获得的金币最大数量。
输入输出样例
输入#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
说明/提示
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.
考虑第一个例子。
- 第一位骑士最弱,因此他无法击杀任何人。这使他仅保留自己最初拥有的那枚金币。
- 第二位骑士可以击杀第一位骑士,并将他的金币加到自己原有的两枚金币上。
- 第三位骑士最强,但他最多只能击杀 k=2 名其他骑士。最优策略是击杀第二位和第四位骑士:2+11+33=46。
- 第四位骑士应击杀第一位和第二位骑士:33+1+2=36。
在第二个例子中,第一位骑士无法击杀任何人,而其余所有骑士都应击杀编号比自己小 1 的那位骑士。
在第三个例子中,只有一位骑士,因此他无法击杀任何人。
输入解题思路,AI测评打分。不知道怎么写?