전공/백준
1026
yha97
2022. 10. 20. 15:14
날짜 : 2022. 10. 20
사용 언어 : python
문제
코드
import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
res = 0
a.sort()
b.sort(reverse = True)
for i in range(n):
res += (a[i] * b[i])
print(res)
알게된 점
- 문제 조건에서 B를 재정렬하지 않는다고 했지만 구체적으로 B의 결괏값이나 매치되는것들을 출력하지 않아도 된다.
- 그래서 서로의 곱의 합을 최소화 하기 위해 A는 오름차순, B는 내림차순으로 정렬하여 곱한 값을 더하면 되는 문제였다.
참고 사이트
-