Algorithm(CodeTree, Python)/완전탐색3
[코드트리 기준을 새로 설정하여 완전탐색] 최대 H 점수 2 Python
by kurooru
2023. 1. 9.
# n, l 입력
n, l = map(int, input().split())
# num_list
num_list = list(map(int, input().split()))
# 함수들
# is_possible(curr_h_point)
def is_possible(curr_h_point):
# pass_cnt
pass_cnt = 0
# chance_point
chance_point = l
# num_list를 돌며
for i in range(n):
# curr_h_point 이상 값은
if num_list[i] >= curr_h_point:
# pass_cnt에 추가
pass_cnt += 1
# curr_h_point와 1 차이나는데, chance_point가 남아있다면
elif num_list[i] + 1 == curr_h_point and chance_point:
# pass_cnt에 추가
pass_cnt += 1
# chance_point 사용
chance_point -= 1
# pass_cnt가 curr_h_point 이상인지 반환
return curr_h_point <= pass_cnt
# 설계
# max_h_point
max_h_point = 0
# 가능한 max_h_point를 기준으로 완전탐색
for i in range(101):
# 현재 h점수가 가능하면
if is_possible(i):
# max_h_point update
max_h_point = i
# 출력
print(max_h_point)