CF1282B1.K for the Price of One (Easy Version)

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easy version of this problem. The only difference is the constraint on kk — the number of gifts in the offer. In this version: k=2k=2.

Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "kk of goods for the price of one" is held in store. Remember, that in this problem k=2k=2.

Using this offer, Vasya can buy exactly kk of any goods, paying only for the most expensive of them. Vasya decided to take this opportunity and buy as many goods as possible for his friends with the money he has.

More formally, for each good, its price is determined by aia_i — the number of coins it costs. Initially, Vasya has pp coins. He wants to buy the maximum number of goods. Vasya can perform one of the following operations as many times as necessary:

  • Vasya can buy one good with the index ii if he currently has enough coins (i.e p≥aip \ge a_i). After buying this good, the number of Vasya's coins will decrease by aia_i, (i.e it becomes p:=p−aip := p - a_i).
  • Vasya can buy a good with the index ii, and also choose exactly k−1k-1 goods, the price of which does not exceed aia_i, if he currently has enough coins (i.e p≥aip \ge a_i). Thus, he buys all these kk goods, and his number of coins decreases by aia_i (i.e it becomes p:=p−aip := p - a_i).

Please note that each good can be bought no more than once.

For example, if the store now has n=5n=5 goods worth a1=2,a2=4,a3=3,a4=5,a5=7a_1=2, a_2=4, a_3=3, a_4=5, a_5=7, respectively, k=2k=2, and Vasya has 66 coins, then he can buy 33 goods. A good with the index 11 will be bought by Vasya without using the offer and he will pay 22 coins. Goods with the indices 22 and 33 Vasya will buy using the offer and he will pay 44 coins. It can be proved that Vasya can not buy more goods with six coins.

Help Vasya to find out the maximum number of goods he can buy.

这是本题的简单版本。唯一的区别在于对 kk(优惠中商品的数量)的约束。在本版本中:k=2k=2。

瓦夏来到商店,为朋友们购买新年礼物。结果他非常幸运——今天商店正在举行“kk 件商品仅需支付其中最贵一件的价格”的优惠活动。注意,在本题中 k=2k=2。

利用该优惠,瓦夏可以恰好购买任意 kk 件商品,但只需支付其中最贵的一件的价格。瓦夏决定抓住这个机会,用自己所拥有的钱尽可能多地为朋友们购买商品。

更形式化地,每件商品的价格为 aia_i(即其花费的硬币数)。初始时,瓦夏有 pp 枚硬币。他希望购买尽可能多的商品。瓦夏可以无限次执行以下任一操作:

  • 若当前硬币数足够(即 p≥aip \ge a_i),瓦夏可以单独购买第 ii 件商品;购买后,他的硬币数减少 aia_i(即变为 p:=p−aip := p - a_i)。
  • 若当前硬币数足够(即 p≥aip \ge a_i),瓦夏可以购买第 ii 件商品,并额外选择恰好 k−1k-1 件价格不超过 aia_i 的商品,从而一次性购买这 kk 件商品;购买后,他的硬币数仅减少 aia_i(即变为 p:=p−aip := p - a_i)。

请注意,每件商品最多只能被购买一次。

例如,若商店当前有 n=5n=5 件商品,价格分别为 a1=2,a2=4,a3=3,a4=5,a5=7a_1=2, a_2=4, a_3=3, a_4=5, a_5=7,且 k=2k=2,瓦夏有 66 枚硬币,则他最多可购买 33 件商品:第 11 件商品不使用优惠单独购买,花费 22 枚硬币;第 22 和第 33 件商品使用优惠一起购买,花费 44 枚硬币(即二者中较贵者的价格)。可以证明,瓦夏无法用 66 枚硬币购买超过 33 件商品。

请帮助瓦夏计算他最多能购买多少件商品。

输入格式

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

The next lines contain a description of tt test cases.

The first line of each test case contains three integers n,p,kn, p, k (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, 1≤p≤2⋅1091 \le p \le 2\cdot10^9, k=2k=2) — the number of goods in the store, the number of coins Vasya has and the number of goods that can be bought by the price of the most expensive of them.

The second line of each test case contains nn integers aia_i (1≤ai≤1041 \le a_i \le 10^4) — the prices of goods.

It is guaranteed that the sum of nn for all test cases does not exceed 2⋅1052 \cdot 10^5. It is guaranteed that in this version of the problem k=2k=2 for all test cases.

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

接下来的若干行描述了 tt 个测试用例。

每个测试用例的第一行包含三个整数 n,p,kn, p, k(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,1≤p≤2⋅1091 \le p \le 2\cdot10^9,k=2k=2)—— 分别表示商店中商品的数量、Vasya 拥有的硬币数量,以及可按其中最贵商品价格购买的商品数量。

每个测试用例的第二行包含 nn 个整数 aia_i(1≤ai≤1041 \le a_i \le 10^4)—— 表示各商品的价格。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。在本题版本中,对所有测试用例均有 k=2k=2。

输出格式

For each test case in a separate line print one integer mm — the maximum number of goods that Vasya can buy.

对于每个测试用例,在单独的一行中输出一个整数 mm —— Vasya 最多能购买的商品数量。

输入输出样例

  • 输入#1

    6
    5 6 2
    2 4 3 5 7
    5 11 2
    2 4 3 5 7
    2 10000 2
    10000 10000
    2 9999 2
    10000 10000
    5 13 2
    8 2 8 2 5
    3 18 2
    1 2 3

    输出#1

    3
    4
    2
    0
    4
    3

输入解题思路,AI测评打分。不知道怎么写?

首页