이것이 코딩테스트다 with 파이썬 - Chp3. 그리디_2. 큰수의 법칙

Alex·2022년 3월 20일
0

이코테 with 파이썬

목록 보기
8/33

2. 큰 수의 법칙

n, m ,k = map(int, input().split())
numbers = list(map(int, input().split()))

numbers.sort()
# sort와 sorted함수 차이점
# sort()와 sorted()의 가장 큰 차이점은 sorted()는 리스트와 문자열 둘 다 적용이 가능하지만 
# sort()는 리스트만 가능하다. sort()로 문자열을 정렬하면 error가 발생하니 주의
# 해당 부분에선 sorted를 사용해도 괜찮은지 
#-> error (AttributeError: 'list' object has no attribute 'sorted'. Did you mean: 'sort'?)
# 리스트에 사용했는데 sorted 왜 에러? 
#-> sorted 함수는 정렬된 결괏값을 입력값에 바로 반영하지 않는 것이 특징. 
#즉, sorted 함수를 활용해 입력값을 정렬한 결과는 얻을 수 있지만, 
#결괏값을 입력값에 따로 할당하지 않는 이상 입력값은 정렬되지 않음.
# https://heytech.tistory.com/61 참조

max1 = numbers[-1]
max2 = numbers[-2]

count = int(m / (k+1)) * k
count += m % (k+1)

result = 0
result += ((count) * max1)
result += ((m-count) * max2)
print(result)

-> 반복되는 수열에 대해서 파악.

profile
With Data or Without Data?

0개의 댓글

관련 채용 정보