Codeforces
New Colony
john.k
2021. 2. 9. 12:32
반응형
Codeforces Round #699 (Div. 2)
B. New Colony
https://codeforces.com/contest/1481/problem/B
Problem - B - Codeforces
codeforces.com
문제 전문은 위 링크에서 확인하실 수 있습니다.
# https://codeforces.com/contest/1481/problem/B
t = int(input())
for _ in range(t):
n, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
idx = 0
# 하나밖에 없다면 바로 사라진다
if len(arr) == 1:
print(-1)
else:
while True:
# 다음 것 보다 낮으면 +1 됨. k가 하나 사라짐.
if arr[idx] < arr[idx + 1]:
arr[idx] += 1
k -= 1
answer = idx
idx = 0
# 다음 것 보다 높거나 같으면 굴러감.
else:
idx += 1
# k가 없다면 끝
if k == 0:
break
# 끝까지 가면 사라진다. 한번 사라지기 시작하면 다 사라짐.
if idx == len(arr) - 1:
answer = -1
break
if answer > -1:
answer += 1
print(answer)
주어진 높이가 하나일 때를 고려하고 주어진 조건대로 구현했습니다
반응형