Codeforces In English По-русски criticalcoding Logout Home Top Catalog Contests Gym…
- User
Codeforces | In English По-русски criticalcoding | Logout
Home Top Catalog Contests Gym Problemset Groups Rating Edu API Calendar Help RayanHello 2025 Contest is running 00:27:13 Add to favourites → Score table Score Problem A 310 Problem B 620 Problem C 929 Problem D 1394 Problem E1 620 Problem E2 1239 Problem F 2168 Problem G 2322 Problem H 2787 Successful hack 100 Unsuccessful hack -50 Unsuccessful submission -50 Resubmission -50
-
If you solve problem on 01:59 from the first attempt
Problems Submit Code My Submissions Status Room Standings Custom Invocation
The problem statement has recently been changed. View the changes. × B. Gorilla and the Exam time limit per test 1 second memory limit per test 256 megabytes
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.
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:
take two integers land r, such that l≤r, and let x be the min(bl,bl+1,…,br) ; then remove all such bi that l≤i≤r and bi=x
from the array, the deleted elements are removed, the indices are renumerated.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≤i≤n) and any integer p, and replace ai with p
.
Help the gorilla to determine the smallest value of f(a)
that can be achieved after such replacements. Input
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤104
) — the number of test cases. The description of the test cases follows.
The first line of each set of input data contains two integers n and k (1≤n≤105, 0≤k≤n) — the length of the array a
and the maximum number of changes, respectively.
The second line of each set of input data contains n integers a1,a2,…,an (1≤ai≤109) — the array a
itself.
It is guaranteed that the sum of the values of n across all sets of input data does not exceed 105
. Output
For each set of input data, output a single integer on a separate line — the smallest possible value of f(a)
. Example Input Copy
6 1 0 48843 3 1 2 3 2 5 3 1 2 3 4 5 7 0 4 7 1 3 2 4 1 11 4 3 2 1 4 4 3 4 2 1 3 3 5 5 1 2 3 4 5
Output Copy
1 1 2 5 2 1
Note
In the first set of input data, f([48843])=1
-
- Assistant