Skip to content

Instantly share code, notes, and snippets.

@krikit
Created April 24, 2015 12:45
Show Gist options
  • Save krikit/6ef4d6cf861ac308d474 to your computer and use it in GitHub Desktop.
Save krikit/6ef4d6cf861ac308d474 to your computer and use it in GitHub Desktop.
import java.io.{FileInputStream, FileOutputStream}
import scala.io.StdIn
object Main extends App {
Console.setIn(new FileInputStream("B-large-practice.in"))
Console.setOut(new FileOutputStream("B-large-practice.out"))
def timeToShare(numCake: Int, numShare: Int): Int = (numCake + (numShare - 1)) / numShare - 1
def timeToEat(numCakes: List[Int], numShare: Int): Int = numCakes.map(timeToShare(_, numShare)).sum + numShare
def minTimeToEat(numCakes: List[Int]): Int = (1 to numCakes.max).map(timeToEat(numCakes, _)).min
val cases = StdIn.readLine().toInt
(1 to cases) foreach { n =>
StdIn.readLine()
val cakes = StdIn.readLine().split(" ").map(_.toInt).toList
println(s"Case #$n: ${minTimeToEat(cakes)}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment