BOJ-Algorithm
백준 9414 - 프로그래밍 대회 전용 부지
bellhundred
2022. 1. 22. 20:14
https://www.acmicpc.net/problem/9414
9414번: 프로그래밍 대회 전용 부지
첫째 줄에 테스트 케이스의 개수 T (1 ≤ T ≤ 10)가 주어진다. 각 테스트 케이스는 땅값 Li가 한 줄에 하나씩 주어지며, 0은 테스트 케이스의 마지막을 나타낸다. 각 테스트 케이스마다 상근이가 구
www.acmicpc.net
import sys
input = sys.stdin.readline
testcase = int(input().strip())
for i in range(testcase):
arr = []
cost = ''
while True:
cost = int(input().strip())
if cost == 0:
break
else:
arr.append(cost)
arr.sort(reverse=True)
total = 0
for i in range(len(arr)):
total+= 2*(arr[i]**(i+1))
if total>5*(10**6):
print("Too expensive")
else:
print(total)
비용을 최소로 부지를 구매하기 위해서는 입력된 부지의 가격을 내림차순으로 정렬한 뒤에 비싼 부지부터 먼저 구매하는 방식이 최소 비용으로 전체 부지를 구매할 수 있는 경우의 수가 된다.