10 lines
321 B
Swift
10 lines
321 B
Swift
import Foundation
|
|
|
|
func solution(_ k:Int, _ m:Int, _ score:[Int]) -> Int {
|
|
let sort: [Int] = score.sorted(by: >)
|
|
return stride(from: m - 1, to: sort.count, by: m).reduce(0){ $0 + sort[$1] * m }
|
|
}
|
|
|
|
print(solution(3, 4, [1, 2, 3, 1, 2, 3, 1])) // 8
|
|
print(solution(4, 3, [4, 1, 2, 2, 4, 4, 4, 4, 1, 2, 4, 2])) // 33
|