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 kk burles as a bonus among nn employees.

It is known that the current salary of the ii-th employee is aia_i and all the values of aia_i in the company are different.

Polycarp wants to distribute the kk burles between nn employees so this month the ii-th employee will be paid not aia_i, but ai+dia_i+d_i (di≥0d_i \ge 0, did_i is an integer), where did_i is the bonus for the ii-th employee. Of course, d1+d2+⋯+dn=kd_1+d_2+\dots+d_n=k.

Polycarp will follow two rules for choosing the values did_i:

  • the relative order of the salaries should not be changed: the employee with originally the highest salary (aia_i is the maximum) should have the highest total payment after receiving their bonus (ai+dia_i+d_i 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+dia_i+d_i).

Help Polycarp decide the non-negative integer bonuses did_i such that:

  • their sum is kk,
  • for each employee, the number of those who receive strictly more than them remains unchanged (that is, if you sort employees by aia_i and by ai+dia_i+d_i, you get the same order of employees),
  • all ai+dia_i + d_i are different,
  • the maximum of the values ai+dia_i+d_i is the minimum possible.

Help Polycarp and print any of the possible answers d1,d2,…,dnd_1, d_2, \dots, d_n.

波利卡普的创业公司首次实现了年度盈利!现在他计划将 kk 卢布作为奖金分配给 nn 名员工。

已知第 ii 名员工当前的工资为 aia_i,且公司中所有 aia_i 的值互不相同。

波利卡普希望将 kk 卢布在 nn 名员工之间分配,使得本月第 ii 名员工实际获得的薪酬不再是 aia_i,而是 ai+dia_i+d_i(其中 di≥0d_i \ge 0,且 did_i 为整数),did_i 即为分配给第 ii 名员工的奖金。显然,必须满足 d1+d2+⋯+dn=kd_1+d_2+\dots+d_n=k。

波利卡普在确定 did_i 的取值时将遵循两条规则:

  • 不得改变工资的相对顺序:原本工资最高者(即 aia_i 为最大值者)在获得奖金后总薪酬也必须最高(即 ai+dia_i+d_i 也为最大值);原本工资排名第二者,在获得奖金后总薪酬也必须排名第二;依此类推。
  • 强调年度盈利是集体努力的结果,波利卡普希望最小化单名员工所能获得的最高总薪酬(即最小化所有 ai+dia_i+d_i 中的最大值)。

请帮助波利卡普确定一组非负整数奖金 did_i,使其满足:

  • 总和为 kk;
  • 对每名员工而言,薪酬严格高于其的人数保持不变(即:若按 aia_i 排序员工,与按 ai+dia_i+d_i 排序员工,所得员工顺序完全一致);
  • 所有 ai+dia_i + d_i 互不相同;
  • ai+dia_i+d_i 的最大值尽可能小。

请帮助波利卡普,并输出任意一组满足条件的解 d1,d2,…,dnd_1, d_2, \dots, d_n。

输入格式

The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases in the input. Then tt test cases follow.

The first line of each test case contains two integers nn and kk (1≤n≤1051 \le n \le 10^5, 1≤k≤1091 \le k \le 10^9) — the number of employees and the total bonus.

The second line of each test case contains nn different integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9), where aia_i is the current salary of the ii-th employee.

It is guaranteed that the sum of all nn values in the input does not exceed 10510^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 输入中测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤1051 \le n \le 10^5,1≤k≤1091 \le k \le 10^9)—— 分别表示员工人数和总奖金数额。

每个测试用例的第二行包含 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9),其中 aia_i 表示第 ii 位员工当前的薪资。

保证输入中所有 nn 值的总和不超过 10510^5。

输出格式

Print the answers to tt test cases in the order they appear in the input. Print each answer as a sequence of non-negative integers d1,d2,…,dnd_1, d_2, \dots, d_n. If there are several answers, print any of them.

按输入中出现的顺序输出 tt 个测试用例的答案。每个答案输出为一串非负整数 d1,d2,…,dnd_1, d_2, \dots, d_n。若存在多个可行答案,输出任意一个即可。

输入输出样例

  • 输入#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测评打分。不知道怎么写?

首页