Last active
December 6, 2015 01:58
-
-
Save handrake/fc31eba503c9e7633238 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.PrintStream | |
import scala.io.Source | |
object gFiles { | |
def solve(pks:Seq[(Long, Long)]): Long = { | |
pks.last match { | |
case (100, r) => r | |
case (_, _) => | |
val (m,n) = pks.dropWhile(_._1 == 0).map { case (p, k) => | |
(100*k/(1+p), 100*k/p)}.unzip | |
if (n.min-m.max == 1) n.min else -1 | |
} | |
} | |
def main(args: Array[String]): Unit = { | |
val INPUT = "B-large-practice.in" | |
// val INPUT = "2.in" | |
val OUTPUT = INPUT.takeWhile(_ != '.') + ".out" | |
val isConsole = false | |
val itr = Source.fromFile(INPUT).getLines() | |
val stream = if (isConsole) Console.out else new PrintStream(OUTPUT) | |
try { | |
val t = itr.next().toInt | |
(1 to t).foreach { x => | |
val n = itr.next().toInt | |
val pks = for(i <- 1 to n) yield { | |
val s = itr.next().split(" ").map(_.toLong) | |
(s(0), s(1)) | |
} | |
stream.println(s"Case #$x: ${solve(pks)}") | |
// println(s"Case #$x: ${solve(pks)}") | |
} | |
} finally { | |
stream.flush() | |
if (!isConsole) stream.close() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment