Created
April 17, 2015 13:06
-
-
Save waynejo/30856a1098126f958911 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("A-large.in")) | |
Console.setOut(new FileOutputStream("A-large.out")) | |
def solve(audiences: String): Int = { | |
def getFakeMensCount(audiences: String, shymens: Int = 0, fakeMens: Int = 0, total: Int): Int = { | |
if (audiences.isEmpty || shymens > total) { | |
fakeMens | |
} else { | |
val shymen = audiences.head.toString.toInt | |
val level = total - audiences.length | |
val fakeMen = if (shymens > level) 0 else level - shymens | |
getFakeMensCount(audiences.tail, shymens + shymen + fakeMen, fakeMens + fakeMen, total) | |
} | |
} | |
getFakeMensCount(audiences, total = audiences.length) | |
} | |
val cases = StdIn.readLine().toInt | |
(1 to cases) foreach { n => | |
val numbers = StdIn.readLine().split(" ")(1) | |
println(s"Case #$n: ${solve(numbers)}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment