-
-
Save krikit/6ef4d6cf861ac308d474 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.{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