https://www.acmicpc.net/problem/16208
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 |
댓글