1415B.md (2229B)
1 Source: https://codeforces.com/problemset/problem/1415/B 2 3 B. Repainting Street 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 There is a street with $n$ houses in a line, numbered from $1$ to $n$. The house $i$ is initially painted in color $c_i$. The street is considered beautiful if all houses are painted in the same color. Tom, the painter, is in charge of making the street beautiful. Tom's painting capacity is defined by an integer, let's call it $k$. 22 23 On one day, Tom can do the following repainting process that consists of two steps: 24 25 1. He chooses two integers $l$ and $r$ such that $ 1 \le l \le r \le n $ and $ r - l + 1 = k $. 26 2. For each house $i$ such that $l \le i \le r$, he can either repaint it with any color he wants, or ignore it and let it keep its current color. 27 28 Note that in the same day Tom can use different colors to repaint different houses. 29 30 Tom wants to know the minimum number of days needed to repaint the street so that it becomes beautiful. 31 32 Input 33 34 The first line of input contains a single integer $t$ ($ 1 \le t \le 10^4$), the number of test cases. Description of test cases follows. 35 36 In the first line of a test case description there are two integers $n$ and $k$ ($1 \le k \le n \le 10^5$). 37 38 The second line contains $n$ space-separated integers. The $i$-th of these integers represents $c_i$ ($1 \le c_i \le 100$), the color which house $i$ is initially painted in. 39 40 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. 41 42 Output 43 44 Print $t$ lines, each with one integer: the minimum number of days Tom needs to make the street beautiful for each test case. 45 46 Example 47 48 Input 49 50 ``` 51 3 52 10 2 53 1 1 2 2 1 1 2 2 2 1 54 7 1 55 1 2 3 4 5 6 7 56 10 3 57 1 3 3 3 3 1 2 1 3 3 58 ``` 59 60 Output 61 62 ``` 63 3 64 6 65 2 66 ``` 67 68 Note 69 70 In the first test case Tom should paint houses 1 and 2 in the first day in color 2, houses 5 and 6 in the second day in color 2, and the last house in color 2 on the third day. 71 72 In the second test case Tom can, for example, spend 6 days to paint houses 1, 2, 4, 5, 6, 7 in color 3. 73 74 In the third test case Tom can paint the first house in the first day and houses 6, 7, and 8 in the second day in color 3.