-
Notifications
You must be signed in to change notification settings - Fork 0
/
New Colony.cpp
59 lines (48 loc) · 1.02 KB
/
New Colony.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// https://codeforces.com/problemset/problem/1481/B
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
ll n , boulders;
cin >> n >> boulders;
ll h[n];
for(int i=0; i<n; i++)
{
cin >> h[i];
}
int pos;
// b is the index of the boulder that is thrown
// m is the position of the current boulder on the mountains
for(ll b=0, m=0; b<boulders;)
{
if(m == n-1)
{
pos = -1;
break; // coz if 1 boulder goes to garbage collection then the remaining too will go down the garbage collection
}
else if(h[m] < h[m+1])
{
h[m] += 1;
pos = m+1;
b += 1;
m = 0;
continue;
}
else
{
m += 1;
continue;
}
}
cout << pos << "\n";
}
int main()
{
ll test;
cin >> test;
while(test--)
{
solve();
}
}