CF1481B New Colony(暴力)

题目任意门
B. New Colony
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.

Input
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.

Output
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.

Example
inputCopy
4
4 3
4 1 2 3
2 7
1 8
4 5
4 1 2 3
3 1
5 3 1
outputCopy
2
1
-1
-1
Note
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.

这道题的意思其实就是说对于一座山,如果下面一个数大于前面的一个数,那么这个增量就留在前面那个数上面,前面的那个数自增1,那么我们现在输入第一行分别为这一组数的大小,和石头的块数,第二行是这些数的大小。
这道题其实暴力模拟就好,但是没切出来,说明太次hhh,还需要学习啊!

#include<iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	int a[1010010];
	int b[1010100];
	while(t--){
		int n,m;
		int cnt=0;//计数用的 
		//我们的cnt其实就是记录我们放了几块石头 
		cin>>n>>m;
		for(int i=1;i<=n;i++)cin>>a[i];
		int ju=1;
		while(ju){
			ju=0;
			//接下来的一步就是寻找是否有符合条件的
			//可以存放石头的数字存在 
			for(int i=1;i<n;i++){
				if(a[i]<a[i+1]){
					b[++cnt]=i;
					a[i]++;
					ju=1;//如果能填入增量,那么说明循环还能继续进行
					//如果不能填入增量,则说明循环无法进行 
					break;
				}
			}
		}
		if(cnt>=m)printf("%d\n",b[m]);//如果存放石头个数大于等于m那么说明我们可以输出
		else printf("-1\n"); //连m块石头都没放,那肯定到最后是放进垃圾填埋系统中
		//必然输出-1 
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值