2주차과제_5. 랜선 자르기

하상철·2021년 4월 22일
0
  1. 문제 링크
    링크텍스트
  2. 풀이 전 계획과 생각
    모든 랜선을 하나도 버리지 않고 자르는 경우가 원하는 만큼의 랜선을 만들수있는 최대의 길이라고 할 수 있으므로 해당 값부터 1씩 줄여가며 각 랜선 마다 만들 수 있는 랜선의 수를 구하고 해당 숫자를 모두 더한 값이 원하는 랜선의 수보다 많아지면 연산을 멈추고 그때의 랜선 길이가 원하는 값이다.
  3. 풀이
def get_max_line_length(line_list,need_line_number):
	total_line_length = 0
	for line in line_list:
		total_line_length += line
	max_length = (total_line_length // need_line_number) + 1
	total_line_number = 0
	while total_line_number < need_line_number:
		max_length -= 1
		total_line_number = 0
		for line in line_list:
			total_line_number += (line // max_length)

	return max_length
		
cur_line, need_line = map(int, input().split(" "))
line_list = []
for num_line in range(cur_line):
	line = int(input())
	line_list.append(line)

max_line_lenth = get_max_line_length(line_list,need_line)
print(max_line_lenth)
  1. 풀이하면서 막혔던 점과 고민
  2. 풀이 후 알게된 개념과 소감
profile
프로그래밍 공부중

0개의 댓글