[백준] 1026 보물(python)

나영·2024년 11월 1일

백준

목록 보기
6/9

✅문제

✏️풀이

n = int(input())

listA = list(map(int, input().split()))
listB = list(map(int, input().split()))

sortedA = sorted(listA, reverse=True)
sortedB = sorted(listB)

s = 0
for i in range(n):
    s += sortedA[i] * sortedB[i]

print(s)
  • A 배열을 내림차순으로 정렬하고, B 배열은 오름차순으로 정렬
  • 정렬된 두 배열의 원소들을 각각 곱하여 총합 S를 계산

⭕정답확인

0개의 댓글