CF1618D.Array and Operations

普及-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an array aa of nn integers, and another integer kk such that 2k≤n2k \le n.

You have to perform exactly kk operations with this array. In one operation, you have to choose two elements of the array (let them be aia_i and aja_j; they can be equal or different, but their positions in the array must not be the same), remove them from the array, and add ⌊aiaj⌋\lfloor \frac{a_i}{a_j} \rfloor to your score, where ⌊xy⌋\lfloor \frac{x}{y} \rfloor is the maximum integer not exceeding xy\frac{x}{y}.

Initially, your score is 00. After you perform exactly kk operations, you add all the remaining elements of the array to the score.

Calculate the minimum possible score you can get.

给你一个包含 nn 个整数的数组 aa,以及另一个满足 2k≤n2k \le n 的整数 kk。

你需要对该数组恰好执行 kk 次操作。每次操作中,你必须选择数组中的两个元素(记为 aia_i 和 aja_j;它们的值可以相等或不同,但它们在数组中的下标必须不同),将这两个元素从数组中移除,并将 ⌊aiaj⌋\lfloor \frac{a_i}{a_j} \rfloor 加入你的得分,其中 ⌊xy⌋\lfloor \frac{x}{y} \rfloor 表示不超过 xy\frac{x}{y} 的最大整数。

初始时,你的得分为 00。在恰好执行完 kk 次操作后,你需将数组中所有剩余元素的值也加到得分中。

请计算你能得到的最小可能得分。

输入格式

The first line of the input contains one integer tt (1≤t≤5001 \le t \le 500) — the number of test cases.

Each test case consists of two lines. The first line contains two integers nn and kk (1≤n≤1001 \le n \le 100; 0≤k≤⌊n2⌋0 \le k \le \lfloor \frac{n}{2} \rfloor).

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5).

输入的第一行包含一个整数 tt(1≤t≤5001 \le t \le 500),表示测试用例的数量。

每个测试用例由两行组成。第一行包含两个整数 nn 和 kk(1≤n≤1001 \le n \le 100;0≤k≤⌊n2⌋0 \le k \le \lfloor \frac{n}{2} \rfloor)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5)。

输出格式

Print one integer — the minimum possible score you can get.

输出一个整数——你能得到的最小可能得分。

输入输出样例

  • 输入#1

    5
    7 3
    1 1 1 2 1 3 1
    5 1
    5 5 5 5 5
    4 2
    1 3 3 7
    2 0
    4 2
    9 2
    1 10 10 1 10 2 7 10 3

    输出#1

    2
    16
    0
    6
    16

说明/提示

Let's consider the example test.

In the first test case, one way to obtain a score of 22 is the following one:

  1. choose a7=1a_7 = 1 and a4=2a_4 = 2 for the operation; the score becomes 0+⌊12⌋=00 + \lfloor \frac{1}{2} \rfloor = 0, the array becomes [1,1,1,1,3][1, 1, 1, 1, 3];
  2. choose a1=1a_1 = 1 and a5=3a_5 = 3 for the operation; the score becomes 0+⌊13⌋=00 + \lfloor \frac{1}{3} \rfloor = 0, the array becomes [1,1,1][1, 1, 1];
  3. choose a1=1a_1 = 1 and a2=1a_2 = 1 for the operation; the score becomes 0+⌊11⌋=10 + \lfloor \frac{1}{1} \rfloor = 1, the array becomes [1][1];
  4. add the remaining element 11 to the score, so the resulting score is 22.

In the second test case, no matter which operations you choose, the resulting score is 1616.

In the third test case, one way to obtain a score of 00 is the following one:

  1. choose a1=1a_1 = 1 and a2=3a_2 = 3 for the operation; the score becomes 0+⌊13⌋=00 + \lfloor \frac{1}{3} \rfloor = 0, the array becomes [3,7][3, 7];
  2. choose a1=3a_1 = 3 and a2=7a_2 = 7 for the operation; the score becomes 0+⌊37⌋=00 + \lfloor \frac{3}{7} \rfloor = 0, the array becomes empty;
  3. the array is empty, so the score doesn't change anymore.

In the fourth test case, no operations can be performed, so the score is the sum of the elements of the array: 4+2=64 + 2 = 6.

我们来考虑示例测试。

在第一个测试用例中,一种得到分数 22 的方法如下:

  1. 选择 a7=1a_7 = 1 和 a4=2a_4 = 2 执行操作;分数变为 0+⌊12⌋=00 + \lfloor \frac{1}{2} \rfloor = 0,数组变为 [1,1,1,1,3][1, 1, 1, 1, 3];
  2. 选择 a1=1a_1 = 1 和 a5=3a_5 = 3 执行操作;分数变为 0+⌊13⌋=00 + \lfloor \frac{1}{3} \rfloor = 0,数组变为 [1,1,1][1, 1, 1];
  3. 选择 a1=1a_1 = 1 和 a2=1a_2 = 1 执行操作;分数变为 0+⌊11⌋=10 + \lfloor \frac{1}{1} \rfloor = 1,数组变为 [1][1];
  4. 将剩余元素 11 加入分数,最终得分为 22。

在第二个测试用例中,无论选择何种操作,最终得分均为 1616。

在第三个测试用例中,一种得到分数 00 的方法如下:

  1. 选择 a1=1a_1 = 1 和 a2=3a_2 = 3 执行操作;分数变为 0+⌊13⌋=00 + \lfloor \frac{1}{3} \rfloor = 0,数组变为 [3,7][3, 7];
  2. 选择 a1=3a_1 = 3 和 a2=7a_2 = 7 执行操作;分数变为 0+⌊37⌋=00 + \lfloor \frac{3}{7} \rfloor = 0,数组变为空;
  3. 数组为空,因此分数不再变化。

在第四个测试用例中,无法执行任何操作,因此分数为数组各元素之和:4+2=64 + 2 = 6。

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

首页