728x90
반응형

A, B 리스트를 받을 때 각각 오름차순, 내림차순으로 정렬한 후 각 요소들의 곱의 합을 구하면 된다.

EX) A = [1,1,1,6,0], B = [2,7,8,3,1] 

A 오름차순 정렬 -> [0,1,1,1,6]

B 내림차순 정렬 -> [8,7,3,2,1]

곱의 합 = 0*8 + 1*7 + 1*3 + 1*2 + 6*1 = 0 + 7 + 3 + 2 + 6 = 18

n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())))
S = 0

for i in range(n):
    S += A[i]*B[i]
print(S)

728x90
반응형

+ Recent posts