CF1297D.Bonus Distribution
普及/提高-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For the first time, Polycarp's startup ended the year with a profit! Now he is about to distribute k burles as a bonus among n employees.
It is known that the current salary of the i-th employee is ai and all the values of ai in the company are different.
Polycarp wants to distribute the k burles between n employees so this month the i-th employee will be paid not ai, but ai+di (di≥0, di is an integer), where di is the bonus for the i-th employee. Of course, d1+d2+⋯+dn=k.
Polycarp will follow two rules for choosing the values di:
- the relative order of the salaries should not be changed: the employee with originally the highest salary (ai is the maximum) should have the highest total payment after receiving their bonus (ai+di is also the maximum), the employee whose salary was originally the second-largest should receive the second-largest total payment after receiving their bonus and so on.
- to emphasize that annual profit is a group effort, Polycarp wants to minimize the maximum total payment to an employee (i.e minimize the maximum value of ai+di).
Help Polycarp decide the non-negative integer bonuses di such that:
- their sum is k,
- for each employee, the number of those who receive strictly more than them remains unchanged (that is, if you sort employees by ai and by ai+di, you get the same order of employees),
- all ai+di are different,
- the maximum of the values ai+di is the minimum possible.
Help Polycarp and print any of the possible answers d1,d2,…,dn.
波利卡普的创业公司首次实现了年度盈利!现在他计划将 k 卢布作为奖金分配给 n 名员工。
已知第 i 名员工当前的工资为 ai,且公司中所有 ai 的值互不相同。
波利卡普希望将 k 卢布在 n 名员工之间分配,使得本月第 i 名员工实际获得的薪酬不再是 ai,而是 ai+di(其中 di≥0,且 di 为整数),di 即为分配给第 i 名员工的奖金。显然,必须满足 d1+d2+⋯+dn=k。
波利卡普在确定 di 的取值时将遵循两条规则:
- 不得改变工资的相对顺序:原本工资最高者(即 ai 为最大值者)在获得奖金后总薪酬也必须最高(即 ai+di 也为最大值);原本工资排名第二者,在获得奖金后总薪酬也必须排名第二;依此类推。
- 强调年度盈利是集体努力的结果,波利卡普希望最小化单名员工所能获得的最高总薪酬(即最小化所有 ai+di 中的最大值)。
请帮助波利卡普确定一组非负整数奖金 di,使其满足:
- 总和为 k;
- 对每名员工而言,薪酬严格高于其的人数保持不变(即:若按 ai 排序员工,与按 ai+di 排序员工,所得员工顺序完全一致);
- 所有 ai+di 互不相同;
- ai+di 的最大值尽可能小。
请帮助波利卡普,并输出任意一组满足条件的解 d1,d2,…,dn。
输入格式
The first line contains an integer t (1≤t≤104) — the number of test cases in the input. Then t test cases follow.
The first line of each test case contains two integers n and k (1≤n≤105, 1≤k≤109) — the number of employees and the total bonus.
The second line of each test case contains n different integers a1,a2,…,an (1≤ai≤109), where ai is the current salary of the i-th employee.
It is guaranteed that the sum of all n values in the input does not exceed 105.
第一行包含一个整数 t(1≤t≤104)—— 输入中测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤105,1≤k≤109)—— 分别表示员工人数和总奖金数额。
每个测试用例的第二行包含 n 个互不相同的整数 a1,a2,…,an(1≤ai≤109),其中 ai 表示第 i 位员工当前的薪资。
保证输入中所有 n 值的总和不超过 105。
输出格式
Print the answers to t test cases in the order they appear in the input. Print each answer as a sequence of non-negative integers d1,d2,…,dn. If there are several answers, print any of them.
按输入中出现的顺序输出 t 个测试用例的答案。每个答案输出为一串非负整数 d1,d2,…,dn。若存在多个可行答案,输出任意一个即可。
输入输出样例
输入#1
5 4 1 3 1 4 2 2 3 10 2 4 1000000000 987654321 1000000000 999999999 500000000 8 9 5 6 1 8 3 4 2 7 6 1 6 3 1 8 5 9
输出#1
0 0 1 0 0 3 134259259 121913582 121913582 621913577 2 2 0 2 0 1 0 2 1 0 0 0 0 0
输入解题思路,AI测评打分。不知道怎么写?