2057B.md (2481B)
1 Source: https://codeforces.com/problemset/problem/2057/B 2 3 B. Gorilla and the Exam 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Due to a shortage of teachers in the senior class of the "T-generation", it was decided to have a huge male gorilla conduct exams for the students. However, it is not that simple; to prove his competence, he needs to solve the following problem. 22 23 For an array $b$, we define the function $f(b)$ as the smallest number of the following operations required to make the array $b$ empty: 24 25 * take two integers $l$ and $r$, such that $l \le r$, and let $x$ be the $\min(b_l, b_{l+1}, \ldots, b_r)$; then 26 * remove all such $b_i$ that $l \le i \le r$ and $b_i = x$ from the array, the deleted elements are removed, the indices are renumerated. 27 28 You are given an array $a$ of length $n$ and an integer $k$. No more than $k$ times, you can choose any index $i$ ($1 \le i \le n$) and any integer $p$, and replace $a_i$ with $p$. 29 30 Help the gorilla to determine the smallest value of $f(a)$ that can be achieved after such replacements. 31 32 Input 33 34 Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows. 35 36 The first line of each set of input data contains two integers $n$ and $k$ ($1 \le n \le 10^5$, $0 \le k \le n$) — the length of the array $a$ and the maximum number of changes, respectively. 37 38 The second line of each set of input data contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the array $a$ itself. 39 40 It is guaranteed that the sum of the values of $n$ across all sets of input data does not exceed $10^5$. 41 42 Output 43 44 For each set of input data, output a single integer on a separate line — the smallest possible value of $f(a)$. 45 46 Example 47 48 Input 49 50 ``` 51 6 52 53 1 0 54 55 48843 56 57 3 1 58 59 2 3 2 60 61 5 3 62 63 1 2 3 4 5 64 65 7 0 66 67 4 7 1 3 2 4 1 68 69 11 4 70 71 3 2 1 4 4 3 4 2 1 3 3 72 73 5 5 74 75 1 2 3 4 5 76 ``` 77 78 Output 79 80 ``` 81 1 82 1 83 2 84 5 85 2 86 1 87 ``` 88 89 Note 90 91 In the first set of input data, $f([48\,843]) = 1$, since the array consists of a single number, and thus it can be removed in one operation. 92 93 In the second set of input data, you can change the second number to $2$, resulting in the array $[2, 2, 2]$, where $f([2, 2, 2]) = 1$, since you can take the entire array as a subarray, the minimum on it is $2$, so we will remove all the $2$s from the array, and the array will become empty.