CF2189A.Table with Numbers

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Peter drew a table of size h×lh \times l, filled with zeros. We will number its rows from 11 to hh from top to bottom, and columns from 11 to ll from left to right. Ned came up with an array of numbers a1,a2,…,ana_1, a_2, \ldots, a_n and wanted to modify the table.

Ned can choose 2k≤n2k \leq n numbers from his array and split them into kk pairs. After that, for each resulting pair x,yx, y, he takes the cell located in row xx and column yy, and adds 11 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×lh \times l 的表格,并用零填充。我们将表格的行从上到下编号为 11 到 hh,列从左到右编号为 11 到 ll。内德构思了一个数字数组 a1,a2,…,ana_1, a_2, \ldots, a_n,并希望对这个表格进行修改。

内德可以从他的数组中选出 2k≤n2k \leq n 个数,并将它们分成 kk 对。随后,对于每一对数 x,yx, y,他找到位于第 xx 行、第 yy 列的单元格,并将该单元格中的数值加 11。如果这样的单元格不存在(即 x>hx > h 或 y>ly > l),则该对数对表格不产生任何影响。

彼得支持内德的这一想法,并请他使表格中所有数字之和尽可能大。请帮助内德计算他所能达到的最大总和。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains three integers nn, hh, and ll (2≤n≤1002 \le n \le 100, 1≤h,l≤10001 \le h, l \le 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 nn numbers a1a_1, a2a_2, …\ldots, ana_n (1≤ai≤10001 \le a_i \le 1000) — the array itself.

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

每个测试用例的第一行包含三个整数 nn、hh 和 ll(2≤n≤1002 \le n \le 100,1≤h,l≤10001 \le h, l \le 1000)—— 分别表示数组的大小、桌子的高度和桌子的宽度。

每个测试用例的第二行包含 nn 个数字 a1a_1、a2a_2、…\ldots、ana_n(1≤ai≤10001 \le a_i \le 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)(1, 1) and add 11 to the number located in row 11 and column 11.

In the second test case, Ned can take the numbers 1,2,2,21, 2, 2, 2 and pair them as follows: (1,2),(2,2)(1, 2), (2, 2). Then, in two cells of the table, there will be a 11, and the sum will be equal to 22. 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)(5, 5). Since such a cell does not exist in the table, the sum of the numbers in the table cannot exceed 00.

In the seventh test case, Ned can pair the numbers like this: (1,1),(1,1)(1, 1), (1, 1). Then the only cell in the table will contain the number 22, and the sum will also be 22. It can be shown that it is not possible to achieve a higher sum.

在第一个测试用例中,Ned 可以选取数对 (1,1)(1, 1),并将第 11 行第 11 列位置上的数加 11。

在第二个测试用例中,Ned 可以选取数字 1,2,2,21, 2, 2, 2,并将它们配对为:(1,2),(2,2)(1, 2), (2, 2)。随后,表格中有两个单元格的值为 11,总和即为 22。可以证明,无法得到更高的总和。

在第五个测试用例中,Ned 唯一可选的数对是 (5,5)(5, 5)。由于表格中并不存在第 55 行第 55 列的单元格,因此表格中数字的总和不可能超过 00。

在第七个测试用例中,Ned 可以将数字如此配对:(1,1),(1,1)(1, 1), (1, 1)。此时表格中唯一的单元格将包含数字 22,总和也为 22。可以证明,无法得到更高的总和。

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

首页