CF2258B1.Carrot Chopdown (Easy Version)

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, you only need to solve the problem for k=1k=1. You can hack only if you solved all versions of this problem.

Alp loves carrots. Since he hasn't eaten lunch yet, he wants to buy a carrot salad to eat outside. However, he has a weird obsession: all the carrots must be the exact same length; otherwise, the salad doesn't look aesthetically pleasing to him. Since he is in the middle of the street and doesn't have a knife, he can't cut the carrots himself. You need to divide all the carrots using your machine and sell them to Alp.

You are given nn delicious carrots with sizes a1,a2,…,ana_1, a_2, \ldots, a_n. You are also given a cutting machine, which works as follows.

  • For each operation, you choose a set of carrots (you can choose chopped carrots again) and a positive integer xx (not necessarily the same for each operation).
  • After that, consider every chosen carrot, let its length be ll. If l≤xl \le x, this carrot is unaffected; otherwise, it is divided into two carrots of sizes xx and l−xl-x.

We'll sell some of the final carrots to an interesting guy who wants them all to be the same length.

We are asking you to determine the maximum number of carrots we can sell after using this machine exactly kk times. Solve the problem for only k=1k=1.

这是该问题的简单版本。两个版本的区别在于,在本版本中,你只需解决 k=1k=1 的情况。仅当你解决了该问题的所有版本后,才可进行 Hack。

阿尔普热爱胡萝卜。由于他尚未吃午饭,他想买一份胡萝卜沙拉,到户外享用。然而,他有一种奇特的执念:所有胡萝卜的长度必须完全相同;否则,沙拉在他看来就不够美观。由于他正身处街道中央,且身上没有刀,因此无法自行切分胡萝卜。你需要使用你的切割机对所有胡萝卜进行分割,并将它们卖给阿尔普。

你被给定 nn 根美味的胡萝卜,其长度分别为 a1,a2,…,ana_1, a_2, \ldots, a_n。你还拥有一台切割机,其工作方式如下:

  • 每次操作中,你选择一组胡萝卜(可以再次选择已被切过的胡萝卜)以及一个正整数 xx(每次操作的 xx 值不一定相同);
  • 然后,对每个被选中的胡萝卜,设其当前长度为 ll:若 l≤xl \le x,则该胡萝卜不受影响;否则,它将被切成两根长度分别为 xx 和 l−xl-x 的胡萝卜。

我们将把最终得到的部分胡萝卜出售给一位特别的顾客,他要求所购胡萝卜长度全部相同。

我们要求你确定:在恰好使用该机器 kk 次之后,最多能卖出多少根胡萝卜。本题只需解决 k=1k=1 的情形。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains nn and mm (1≤n,m≤2⋅1051 \le n,m \le 2 \cdot 10^5), denoting the number of carrots and the maximum possible length of a carrot.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤m1 \le a_i \le m), denoting the initial carrot sizes.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5 and the sum of mm over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \le n,m \le 2 \cdot 10^5),分别表示胡萝卜的数量以及胡萝卜可能的最大长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤m1 \le a_i \le m),表示每根胡萝卜的初始长度。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5,且所有测试用例中 mm 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer — the answer for k=1k=1.

对于每个测试用例,输出一个整数——即 k=1k=1 时的答案。

输入输出样例

  • 输入#1

    6
    5 4
    1 2 3 4 4
    5 8
    1 1 8 8 8
    1 8
    6
    7 9
    1 7 5 1 7 5 3
    4 1
    1 1 1 1
    3 5
    3 1 5

    输出#1

    6
    6
    2
    7
    4
    3

说明/提示

In the first test case, the given carrots are [1,2,3,4,4][1, 2, 3, 4, 4].

For k=1k=1, it is best to choose x=2x=2 with the set [2,3,4,4][2, 3, 4, 4]. After the operation, we'll get [1,2,2,1,2,2,2,2][1, 2, 2, 1, 2, 2, 2, 2]. We can sell 66 carrots of length 22.

在第一个测试用例中,给定的胡萝卜长度为 [1,2,3,4,4][1, 2, 3, 4, 4]。

当 k=1k=1 时,最优选择是取 x=2x=2,对应集合为 [2,3,4,4][2, 3, 4, 4]。执行操作后,我们将得到 [1,2,2,1,2,2,2,2][1, 2, 2, 1, 2, 2, 2, 2]。此时我们可以售出 66 根长度为 22 的胡萝卜。

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

首页