CF2161C.Loyalty
普及-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
No Loyalty No Royalty (c)
You are a customer in a store and want to buy n items. Each item i has a price ai such that 1≤ai≤X, where X is a loyalty factor.
Your loyalty level in the store is defined as ⌊XS⌋, where S is the total cost of items purchased so far. Initially, S=0.
If you buy an item with price p and your loyalty level increases as a result of this purchase, you earn p bonus points.
Your task is to find the maximum number of bonus points you can earn by choosing an optimal order of purchase for the items.
无忠诚,无特权(c)
你是一家商店的顾客,想要购买 n 件商品。每件商品 i 的价格为 ai,满足 1≤ai≤X,其中 X 是忠诚度因子。
你在该商店的忠诚度定义为 ⌊XS⌋,其中 S 是截至目前已购商品的总花费。初始时,S=0。
若你购买一件价格为 p 的商品,且此次购买导致你的忠诚度提升,则你将获得 p 点奖励积分。
你的任务是:通过选择商品购买顺序,使得所获奖励积分总数最大。请计算该最大值。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤2⋅104). The description of the test cases follows.
The first line of each test case contains two integers n (1≤n≤105) and X (1≤X≤109) — the number of items and the loyalty factor.
The second line of each test case contains n integers a1, a2, …, an (1≤ai≤X) — the prices of the items.
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤2⋅104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n(1≤n≤105)和 X(1≤X≤109)——分别表示物品数量和忠诚度因子。
每个测试用例的第二行包含 n 个整数 a1, a2, …, an(1≤ai≤X)——表示各物品的价格。
保证所有测试用例中 n 的总和不超过 105。
输出格式
For each test case, output two lines.
The first line should contain a single integer — the maximum number of bonus points that can be earned.
The second line should contain n integers — the prices of the items in an order of purchase that maximizes the number of bonus points.
If there are several orders that maximize the number of bonus points, you can output any of them.
对于每个测试用例,输出两行。
第一行应包含一个整数——能够获得的最大奖励积分数量。
第二行应包含 n 个整数——一种能最大化奖励积分数量的商品购买顺序对应的价格。
如果存在多种能最大化奖励积分数量的购买顺序,输出其中任意一种即可。
输入输出样例
输入#1
7 10 2 1 2 1 2 1 2 1 2 1 2 5 10 2 2 2 2 5 11 23 5 5 22 1 21 2 10 3 1 1 2 1 1 1 1 17 11 3 100 44 32 1 16 100500 42801 73112 95296 68791 42217 21871 29316 84405 24273 42894 63370 53473 57156 61369 80 27290
输出#1
12 1 2 2 2 2 2 1 1 1 1 5 2 2 2 2 5 53 1 1 5 2 1 2 5 3 10 21 22 1 1 0 11 0 44 32 1 503499 53473 42894 80 57156 42801 61369 42217 63370 29316 68791 27290 73112 24273 84405 21871 95296
说明/提示
In the first test case:
- After buying the first item S=1, loyalty level is 0;
- After buying the second item S=3, this increases loyalty level to 1 and earns 2 bonus points;
- After buying the third item S=5, this increases loyalty level to 2 and earns 2 bonus points;
- After buying the fourth item S=7, this increases loyalty level to 3 and earns 2 bonus points;
- After buying the fifth item S=9, this increases loyalty level to 4 and earns 2 bonus points;
- After buying the sixth item S=11, this increases loyalty level to 5 and earns 2 bonus points;
- After buying the seventh item S=12, this increases loyalty level to 6 and earns 1 bonus point;
- After buying the eighth item S=13;
- After buying the ninth item S=14, this increases loyalty level to 7 and earns 1 bonus point;
- After buying the tenth item S=15.
Overall we got 12 bonus points.
In the second test case:
- After buying the first four items S=8, loyalty level is 0;
- After buying the last item S=13, this increases loyalty level to 1 and earns 5 bonus points.
In the third test case:
- After buying the first eight items S=20, loyalty level is 0;
- After buying the ninth item S=30, this increases loyalty level to 1 and earns 10 bonus points;
- After buying the tenth item S=51, this increases loyalty level to 2 and earns 21 bonus points;
- After buying the eleventh item S=73, this increases loyalty level to 3 and earns 22 bonus points.
在第一个测试用例中:
- 购买第一件商品后,S=1,忠诚度等级为 0;
- 购买第二件商品后,S=3,忠诚度等级提升至 1,并获得 2 点奖励积分;
- 购买第三件商品后,S=5,忠诚度等级提升至 2,并获得 2 点奖励积分;
- 购买第四件商品后,S=7,忠诚度等级提升至 3,并获得 2 点奖励积分;
- 购买第五件商品后,S=9,忠诚度等级提升至 4,并获得 2 点奖励积分;
- 购买第六件商品后,S=11,忠诚度等级提升至 5,并获得 2 点奖励积分;
- 购买第七件商品后,S=12,忠诚度等级提升至 6,并获得 1 点奖励积分;
- 购买第八件商品后,S=13;
- 购买第九件商品后,S=14,忠诚度等级提升至 7,并获得 1 点奖励积分;
- 购买第十件商品后,S=15。
总计获得 12 点奖励积分。
在第二个测试用例中:
- 购买前四件商品后,S=8,忠诚度等级为 0;
- 购买最后一件商品后,S=13,忠诚度等级提升至 1,并获得 5 点奖励积分。
在第三个测试用例中:
- 购买前八件商品后,S=20,忠诚度等级为 0;
- 购买第九件商品后,S=30,忠诚度等级提升至 1,并获得 10 点奖励积分;
- 购买第十件商品后,S=51,忠诚度等级提升至 2,并获得 21 点奖励积分;
- 购买第十一商品后,S=73,忠诚度等级提升至 3,并获得 22 点奖励积分。
输入解题思路,AI测评打分。不知道怎么写?