Skip to content

Instantly share code, notes, and snippets.

@handrake
Created December 4, 2015 13:11
Show Gist options
  • Save handrake/7dea689ce9cf83019ed8 to your computer and use it in GitHub Desktop.
Save handrake/7dea689ce9cf83019ed8 to your computer and use it in GitHub Desktop.
import java.io.PrintStream
import scala.io.Source
object gFiles {
def solve(pks:Seq[(Long, Long)]): Long = {
if (pks.map(x => x._1).max == 100) {
println(s"terminating at ${pks.last._2}")
return pks.last._2
}
val x = pks.map { y =>
val p = y._1
val k = y._2
val a = (k.toDouble * 100 / (1 + p)).ceil.toLong + (if (100 * k % (1 + p) == 0) 1 else 0)
val b = if (k == 0) Long.MaxValue else (100 * k.toDouble / p).floor.toLong
println(s"${a} : ${b}")
(a,b)
}
val m = x.map( y => y._1).max
val n = x.map( y => y._2).min
println(s"(m,n) = ${m} : ${n}")
if (m == n) m else -1
}
def main(args: Array[String]): Unit = {
val INPUT = "B-small-practice.in"
// val INPUT = "4.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