Created
May 15, 2015 13:15
-
-
Save waynejo/67a2ddb8ca78c200ab47 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
object Main extends App { | |
Console.setIn(new FileInputStream("example.in")) | |
Console.setIn(new FileInputStream("A-large-practice.in")) | |
//Console.setOut(new FileOutputStream("A-large-practice.out")) | |
def solve(v: List[Int]): (Int, Int) = { | |
val diff = (v.init, v.tail).zipped.map(_ - _ max 0) | |
(diff.sum, v.init.map(x => diff.max min x ).sum) | |
} | |
val cases = StdIn.readLine().toInt | |
(1 to cases) foreach { n => | |
StdIn.readLine() | |
val nums = StdIn.readLine().split(" ").map(_.toInt).toList | |
val (a, b) = solve(nums) | |
println(s"Case #$n: $a $b") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment