1481B.md (3147B)
1 Source: https://codeforces.com/problemset/problem/1481/B 2 3 B. New Colony 4 5 time limit per test 6 7 2 seconds 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 After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you). 22 23  24 25 You are given an array $h_1, h_2, \dots, h_n$, where $h_i$ is the height of the $i$-th mountain, and $k$ — the number of boulders you have. 26 27 You will start throwing boulders from the top of the first mountain one by one and they will roll as follows (let's assume that the height of the current mountain is $h_i$): 28 29 * if $h_i \ge h_{i + 1}$, the boulder will roll to the next mountain; 30 * if $h_i \lt h_{i + 1}$, the boulder will stop rolling and increase the mountain height by $1$ ($h_i = h_i + 1$); 31 * if the boulder reaches the last mountain it will fall to the waste collection system and disappear. 32 33 You want to find the position of the $k$-th boulder or determine that it will fall into the waste collection system. 34 35 Input 36 37 The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. 38 39 Each test case consists of two lines. The first line in each test case contains two integers $n$ and $k$ ($1 \le n \le 100$; $1 \le k \le 10^9$) — the number of mountains and the number of boulders. 40 41 The second line contains $n$ integers $h_1, h_2, \dots, h_n$ ($1 \le h_i \le 100$) — the height of the mountains. 42 43 It is guaranteed that the sum of $n$ over all test cases does not exceed $100$. 44 45 Output 46 47 For each test case, print $-1$ if the $k$-th boulder will fall into the collection system. Otherwise, print the position of the $k$-th boulder. 48 49 Example 50 51 Input 52 53 ``` 54 4 55 4 3 56 4 1 2 3 57 2 7 58 1 8 59 4 5 60 4 1 2 3 61 3 1 62 5 3 1 63 ``` 64 65 Output 66 67 ``` 68 2 69 1 70 -1 71 -1 72 ``` 73 74 Note 75 76 Let's simulate the first case: 77 78 * The first boulder starts at $i = 1$; since $h_1 \ge h_2$ it rolls to $i = 2$ and stops there because $h_2 \lt h_3$. 79 * The new heights are $[4,2,2,3]$. 80 * The second boulder starts at $i = 1$; since $h_1 \ge h_2$ the boulder rolls to $i = 2$; since $h_2 \ge h_3$ the boulder rolls to $i = 3$ and stops there because $h_3 \lt h_4$. 81 * The new heights are $[4,2,3,3]$. 82 * The third boulder starts at $i = 1$; since $h_1 \ge h_2$ it rolls to $i = 2$ and stops there because $h_2 \lt h_3$. 83 * The new heights are $[4,3,3,3]$. 84 85 The positions where each boulder stopped are the following: $[2,3,2]$. 86 87 In the second case, all $7$ boulders will stop right at the first mountain rising its height from $1$ to $8$. 88 89 The third case is similar to the first one but now you'll throw $5$ boulders. The first three will roll in the same way as in the first test case. After that, mountain heights will be equal to $[4, 3, 3, 3]$, that's why the other two boulders will fall into the collection system. 90 91 In the fourth case, the first and only boulders will fall straight into the collection system.