-
-
Save sangkeon/a6a5cc8463781894393a 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.{FileOutputStream, FileReader} | |
object gFiles extends App { | |
// val fileName = "sample" | |
val fileName = "B-large-practice" | |
Console.setIn(new FileReader(fileName + ".in")) | |
Console.setOut(new FileOutputStream(fileName +".out")) | |
case class Progress(percent:Long, numFile:Long) | |
case class Range(gt:Long, lte:Long) | |
def progressToRange(prog:Progress) : Range = { | |
if(prog.percent == 0) Range(0, Long.MaxValue) | |
else if(prog.percent == 100) Range(prog.numFile -1, prog.numFile) | |
else { | |
val gt = prog.numFile * 100 / (1 + prog.percent) | |
val lte = prog.numFile * 100 / prog.percent | |
Range(gt, lte) | |
} | |
} | |
def solve(progs:IndexedSeq[Progress]) : Long = { | |
val ranges = progs.map(p => progressToRange(p)).toList | |
val gt = ranges.map(x => x.gt).max | |
val lte = ranges.map(_.lte).min | |
// for(i <- 0 until progs.size) { | |
// Console.println(progs(i) + " " + ranges(i)) | |
// } | |
// Console println(gt + "< ans <=" + lte) | |
if(gt + 1 == lte) lte else -1 | |
} | |
val testCases = Console.readLine().toInt | |
for( i <- 1 to testCases ) { | |
val numProgress = Console.readLine().toInt | |
val progresses = for( j <- 1 to numProgress) yield { | |
val tokens = Console.readLine.split(" ").map(_.toLong) | |
Progress(tokens(0), tokens(1)) | |
} | |
val result = solve(progresses) | |
Console.println(f"Case #$i: $result") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment