/TextBox.scala Secret
Created
January 23, 2015 13:06
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 scala.io.Source | |
import java.io.PrintWriter | |
object TextMessage { | |
val in = Source.fromFile("small.in").getLines | |
val out = new PrintWriter("small.out") | |
case class TestCase(p: Int, k: Int, l: Int, freq: List[Int]) { | |
def solve: Int = { | |
val l = freq.sorted.reverse | |
var currentPlacement: Int = 1 | |
var sum = 0 | |
for (i <- 0 until l.size) { | |
if (i % k == 0 && i != 0) { | |
currentPlacement += 1 | |
} | |
sum += currentPlacement * l(i) | |
} | |
sum | |
} | |
} | |
def main(args: Array[String]) { | |
val nOfTestCases = in.next.toInt | |
val tests = for { | |
i <- 1 to nOfTestCases | |
val Array(p, k, l) = in.next.split(" ").map(_.toInt) | |
val freq = in.next.split(" ").map(_.toInt).toList | |
} yield { | |
TestCase(p, k, l, freq) | |
} | |
tests.map(_.solve).zipWithIndex.map(t => s"Case #${t._2 + 1}: ${t._1}").foreach { o => out.println(o); println(o) } | |
out.flush | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment