CF2189A.Table with Numbers
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Peter drew a table of size h×l, filled with zeros. We will number its rows from 1 to h from top to bottom, and columns from 1 to l from left to right. Ned came up with an array of numbers a1,a2,…,an and wanted to modify the table.
Ned can choose 2k≤n numbers from his array and split them into k pairs. After that, for each resulting pair x,y, he takes the cell located in row x and column y, and adds 1 to the number in that cell. If such a cell does not exist, then this pair does nothing to the table.
Peter supported Ned's initiative and asked him to maximize the sum of the numbers in the table. Help Ned understand what the maximum sum he can achieve is.
彼得绘制了一个大小为 h×l 的表格,并用零填充。我们将表格的行从上到下编号为 1 到 h,列从左到右编号为 1 到 l。内德构思了一个数字数组 a1,a2,…,an,并希望对这个表格进行修改。
内德可以从他的数组中选出 2k≤n 个数,并将它们分成 k 对。随后,对于每一对数 x,y,他找到位于第 x 行、第 y 列的单元格,并将该单元格中的数值加 1。如果这样的单元格不存在(即 x>h 或 y>l),则该对数对表格不产生任何影响。
彼得支持内德的这一想法,并请他使表格中所有数字之和尽可能大。请帮助内德计算他所能达到的最大总和。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤500). The description of the test cases follows.
The first line of each test case contains three integers n, h, and l (2≤n≤100, 1≤h,l≤1000) — the size of the array, the height of the table, and the width of the table, respectively.
The second line of each test case contains n numbers a1, a2, …, an (1≤ai≤1000) — the array itself.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤500)。随后是各测试用例的描述。
每个测试用例的第一行包含三个整数 n、h 和 l(2≤n≤100,1≤h,l≤1000)—— 分别表示数组的大小、桌子的高度和桌子的宽度。
每个测试用例的第二行包含 n 个数字 a1、a2、…、an(1≤ai≤1000)—— 即该数组本身。
输出格式
For each test case, output the maximum possible sum of the numbers in the table.
对于每个测试用例,输出表格中数字可能的最大和。
输入输出样例
输入#1
7 2 1 1 1 1 5 2 2 1 2 2 3 2 8 4 2 7 2 2 2 3 4 4 2 7 3 6 10 4 1 3 5 4 6 2 4 4 5 5 7 6 3 10 4 1 3 5 4 6 4 1 1 1 1 1 1
输出#1
1 2 3 2 0 2 2
说明/提示
In the first test case, Ned can take the pair (1,1) and add 1 to the number located in row 1 and column 1.
In the second test case, Ned can take the numbers 1,2,2,2 and pair them as follows: (1,2),(2,2). Then, in two cells of the table, there will be a 1, and the sum will be equal to 2. It can be shown that it is not possible to achieve a higher sum.
In the fifth test case, the only pair that Ned can take is (5,5). Since such a cell does not exist in the table, the sum of the numbers in the table cannot exceed 0.
In the seventh test case, Ned can pair the numbers like this: (1,1),(1,1). Then the only cell in the table will contain the number 2, and the sum will also be 2. It can be shown that it is not possible to achieve a higher sum.
在第一个测试用例中,Ned 可以选取数对 (1,1),并将第 1 行第 1 列位置上的数加 1。
在第二个测试用例中,Ned 可以选取数字 1,2,2,2,并将它们配对为:(1,2),(2,2)。随后,表格中有两个单元格的值为 1,总和即为 2。可以证明,无法得到更高的总和。
在第五个测试用例中,Ned 唯一可选的数对是 (5,5)。由于表格中并不存在第 5 行第 5 列的单元格,因此表格中数字的总和不可能超过 0。
在第七个测试用例中,Ned 可以将数字如此配对:(1,1),(1,1)。此时表格中唯一的单元格将包含数字 2,总和也为 2。可以证明,无法得到更高的总和。
输入解题思路,AI测评打分。不知道怎么写?