Created
January 2, 2015 13:07
-
-
Save daclouds/6d468fcf376225d112f8 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.{BufferedReader, FileReader} | |
object DataPacking extends App { | |
val input = new BufferedReader(new FileReader("A-large-practice.in")) | |
val T = input.readLine().toInt | |
for (i <- 1 to T) { | |
val size = input.readLine.split(" ")(1).toInt | |
val arr = input.readLine.split(" ").map(_.toInt).sorted.toBuffer | |
var cnt = arr.length | |
while (arr.nonEmpty) { | |
val big = arr.last | |
arr.remove(arr.length-1) | |
val idx = arr.lastIndexWhere(_ <= size - big) | |
if (idx != -1) { | |
cnt -= 1 | |
arr.remove(idx) | |
} | |
} | |
println(s"Case #$i: $cnt") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment