import scala.collection.mutable import scala.io.StdIn object Main { def main(args:Array[String]) = { val n = StdIn.readInt() val a = StdIn.readLine().split(" ").map(_.toInt).+:(1000000000) val pq = new mutable.PriorityQueue[(Int,Int)]()(Ordering.Tuple2[Int,Int].reverse) for (v <- a) pq.+=((v,0)) val b = StdIn.readLine().split(" ").map(_.toInt/2) println( (0 until n).map { i => val q = pq.clone() val (h:Array[Int], t:Array[Int]) = b.splitAt(i).swap h.++(t).foreach { j => val (l, c) = q.dequeue() q.enqueue((l + j, c + 1)) } q.map(_._2).max }.min ) } }