Skip to content

Instantly share code, notes, and snippets.

@waynejo
Created May 15, 2015 13:15
Show Gist options
  • Save waynejo/67a2ddb8ca78c200ab47 to your computer and use it in GitHub Desktop.
Save waynejo/67a2ddb8ca78c200ab47 to your computer and use it in GitHub Desktop.
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