Skip to content

Instantly share code, notes, and snippets.

@daclouds
Created January 2, 2015 13:07
Show Gist options
  • Save daclouds/6d468fcf376225d112f8 to your computer and use it in GitHub Desktop.
Save daclouds/6d468fcf376225d112f8 to your computer and use it in GitHub Desktop.
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