-
-
Save anonymous/884ec745c0afd67c2aa7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.{FileOutputStream, FileInputStream} | |
import scala.io.StdIn | |
object Main extends App { | |
Console.setIn(new FileInputStream("A-large-practice.in")) | |
Console.setOut(new FileOutputStream("A-large-practice.out")) | |
def solve(k: Int, frequency: Array[Long]) : Long = frequency.sortWith(_ > _) | |
.grouped(k.toInt).zipWithIndex | |
.foldLeft(0L)((acc, x) => acc + x._1.sum * (x._2 + 1)) | |
val cases = StdIn.readLine().toInt | |
(1 to cases) foreach {n => | |
val Array(_, k, _) = StdIn.readLine().split(" ") | |
val frequency = StdIn.readLine().split(" ").map(_.toLong) | |
println(s"Case #$n: ${solve(k.toInt, frequency)}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment