codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1618D.md (2709B)


      1 Source: https://codeforces.com/problemset/problem/1618/D
      2 
      3 D. Array and Operations
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given an array $a$ of $n$ integers, and another integer $k$ such that $2k \le n$.
     22 
     23 You have to perform exactly $k$ operations with this array. In one operation, you have to choose two elements of the array (let them be $a_i$ and $a_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 $\lfloor \frac{a_i}{a_j} \rfloor$ to your score, where $\lfloor \frac{x}{y} \rfloor$ is the maximum integer not exceeding $\frac{x}{y}$.
     24 
     25 Initially, your score is $0$. After you perform exactly $k$ operations, you add all the remaining elements of the array to the score.
     26 
     27 Calculate the minimum possible score you can get.
     28 
     29 Input
     30 
     31 The first line of the input contains one integer $t$ ($1 \le t \le 500$) — the number of test cases.
     32 
     33 Each test case consists of two lines. The first line contains two integers $n$ and $k$ ($1 \le n \le 100$; $0 \le k \le \lfloor \frac{n}{2} \rfloor$).
     34 
     35 The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$).
     36 
     37 Output
     38 
     39 Print one integer — the minimum possible score you can get.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 5
     47 7 3
     48 1 1 1 2 1 3 1
     49 5 1
     50 5 5 5 5 5
     51 4 2
     52 1 3 3 7
     53 2 0
     54 4 2
     55 9 2
     56 1 10 10 1 10 2 7 10 3
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 2
     63 16
     64 0
     65 6
     66 16
     67 ```
     68 
     69 Note
     70 
     71 Let's consider the example test.
     72 
     73 In the first test case, one way to obtain a score of $2$ is the following one:
     74 
     75 1. choose $a_7 = 1$ and $a_4 = 2$ for the operation; the score becomes $0 + \lfloor \frac{1}{2} \rfloor = 0$, the array becomes $[1, 1, 1, 1, 3]$;
     76 2. choose $a_1 = 1$ and $a_5 = 3$ for the operation; the score becomes $0 + \lfloor \frac{1}{3} \rfloor = 0$, the array becomes $[1, 1, 1]$;
     77 3. choose $a_1 = 1$ and $a_2 = 1$ for the operation; the score becomes $0 + \lfloor \frac{1}{1} \rfloor = 1$, the array becomes $[1]$;
     78 4. add the remaining element $1$ to the score, so the resulting score is $2$.
     79 
     80 In the second test case, no matter which operations you choose, the resulting score is $16$.
     81 
     82 In the third test case, one way to obtain a score of $0$ is the following one:
     83 
     84 1. choose $a_1 = 1$ and $a_2 = 3$ for the operation; the score becomes $0 + \lfloor \frac{1}{3} \rfloor = 0$, the array becomes $[3, 7]$;
     85 2. choose $a_1 = 3$ and $a_2 = 7$ for the operation; the score becomes $0 + \lfloor \frac{3}{7} \rfloor = 0$, the array becomes empty;
     86 3. the array is empty, so the score doesn't change anymore.
     87 
     88 In the fourth test case, no operations can be performed, so the score is the sum of the elements of the array: $4 + 2 = 6$.