17 lines
451 B
Swift
17 lines
451 B
Swift
if let N = Int(readLine() ?? ""),
|
|
let input1 = readLine(), let input2 = readLine(),
|
|
let A = input1.split(separator: " ").compactMap({Int($0)}) as? [Int],
|
|
let B = input2.split(separator: " ").compactMap({Int($0)}) as? [Int],
|
|
A.count == N, B.count == N
|
|
{
|
|
let sortedA = A.sorted()
|
|
let sortedB = B.sorted(by: >)
|
|
|
|
var result: Int = 0
|
|
for i in 0..<N {
|
|
result += sortedA[i] * sortedB[i]
|
|
}
|
|
|
|
print(result)
|
|
}
|