https://www.acmicpc.net/problem/16208
16208번: 귀찮음
현우는 무슨 이유에선지 길이 a1, ..., an의, 총 n개의 쇠막대가 필요해졌다. 하지만 그가 가진 것은 길이 a1+...+an의 하나의 쇠막대뿐이었다. 현우는 이 막대를 직접 잘라서 원래 필요하던 n개의 쇠
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
def sol(n, nums):
sum_nums = sum(nums)
nums.sort()
answer = 0
for i in range(n):
answer += (sum_nums-nums[i])*nums[i]
sum_nums -= nums[i]
return answer
if __name__ == '__main__':
n = int(input())
nums = list(map(int, input().split()))
print(sol(n, nums))
|
cs |
두수의 합이 고정되있는데 곱을 최소화 하려면 두수의 차가 가장 커야 합니다.
The sum of the two numbers is fixed, but the difference between the two numbers must be the greatest to minimize the product.
반응형
'python-algorithm' 카테고리의 다른 글
백준 16360 Go Latin (0) | 2022.12.13 |
---|---|
백준 26307 Correct (0) | 2022.12.13 |
백준 19947 투자의 귀재 배주형 (0) | 2022.12.12 |
백준 13333 Q-인덱스 (0) | 2022.12.12 |
백준 14912 숫자 빈도수 (0) | 2022.12.10 |
댓글