CF1481B.New Colony
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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).

You are given an array h1,h2,…,hn, where hi is the height of the i-th mountain, and k — the number of boulders you have.
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 hi):
- if hi≥hi+1, the boulder will roll to the next mountain;
- if hi<hi+1, the boulder will stop rolling and increase the mountain height by 1 (hi=hi+1);
- if the boulder reaches the last mountain it will fall to the waste collection system and disappear.
You want to find the position of the k-th boulder or determine that it will fall into the waste collection system.
到达目的地后,你想在新星球上建立一个新的殖民地。由于该星球上有很多山脉,而殖民地必须建在平坦的地面上,因此你决定用巨石来压平这些山脉(你仍在梦中,所以这对你来说是合理的)。

你被给定一个数组 h1,h2,…,hn,其中 hi 表示第 i 座山的高度,以及一个整数 k —— 你所拥有的巨石数量。
你将从第一座山的山顶开始,逐个投掷巨石,巨石的滚动规则如下(假设当前山的高度为 hi):
- 若 hi≥hi+1,则巨石将滚向下一座山;
- 若 hi<hi+1,则巨石将停止滚动,并使当前山的高度增加 1(即 hi=hi+1);
- 若巨石到达最后一座山,则它将落入废料收集系统并消失。
你需要找出第 k 颗巨石最终停留的位置,或者判定它是否会落入废料收集系统。
输入格式
The first line contains a single integer t (1≤t≤100) — the number of test cases.
Each test case consists of two lines. The first line in each test case contains two integers n and k (1≤n≤100; 1≤k≤109) — the number of mountains and the number of boulders.
The second line contains n integers h1,h2,…,hn (1≤hi≤100) — the height of the mountains.
It is guaranteed that the sum of n over all test cases does not exceed 100.
第一行包含一个整数 t(1≤t≤100)—— 测试用例的数量。
每个测试用例由两行组成。每个测试用例的第一行包含两个整数 n 和 k(1≤n≤100;1≤k≤109)—— 山峰的数量和巨石的数量。
每个测试用例的第二行包含 n 个整数 h1,h2,…,hn(1≤hi≤100)—— 各山峰的高度。
保证所有测试用例中 n 的总和不超过 100。
输出格式
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.
对于每个测试用例,如果第 k 个石块会落入收集系统,则输出 −1;否则,输出第 k 个石块的位置。
输入输出样例
输入#1
4 4 3 4 1 2 3 2 7 1 8 4 5 4 1 2 3 3 1 5 3 1
输出#1
2 1 -1 -1
说明/提示
Let's simulate the first case:
- The first boulder starts at i=1; since h1≥h2 it rolls to i=2 and stops there because h2<h3.
- The new heights are [4,2,2,3].
- The second boulder starts at i=1; since h1≥h2 the boulder rolls to i=2; since h2≥h3 the boulder rolls to i=3 and stops there because h3<h4.
- The new heights are [4,2,3,3].
- The third boulder starts at i=1; since h1≥h2 it rolls to i=2 and stops there because h2<h3.
- The new heights are [4,3,3,3].
The positions where each boulder stopped are the following: [2,3,2].
In the second case, all 7 boulders will stop right at the first mountain rising its height from 1 to 8.
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.
In the fourth case, the first and only boulders will fall straight into the collection system.
我们来模拟第一种情况:
- 第一个巨石从 i=1 处开始;由于 h1≥h2,它滚落到 i=2 处,并因 h2<h3 而在此停止。
- 新的高度数组为 [4,2,2,3]。
- 第二个巨石从 i=1 处开始;由于 h1≥h2,它滚落到 i=2 处;又因 h2≥h3,它继续滚落到 i=3 处,并因 h3<h4 而在此停止。
- 新的高度数组为 [4,2,3,3]。
- 第三个巨石从 i=1 处开始;由于 h1≥h2,它滚落到 i=2 处,并因 h2<h3 而在此停止。
- 新的高度数组为 [4,3,3,3]。
每个巨石最终停止的位置依次为:[2,3,2]。
在第二种情况下,全部 7 个巨石都将停在第一座山峰处,该山峰高度由 1 上升至 8。
第三种情况与第一种类似,但现在你将投掷 5 个巨石。前三个巨石的滚动方式与第一个测试用例完全相同。此后,山峰高度变为 [4,3,3,3],因此其余两个巨石将直接落入收集系统。
在第四种情况下,第一个(也是唯一一个)巨石将直接落入收集系统。
输入解题思路,AI测评打分。不知道怎么写?