import java.io.PrintWriter fun main() { val (n, q) = readln().split(" ").map { it.toInt() } val a = readln().split(" ").map { it.toInt() }.toIntArray() val s = Array(q) { readln().toInt() } val pList = (0 until n).map { it -> (1..a[it]).map { it.toLong() } .let { P(it.size, it.sum(), cumulativeSum(it)) } } val wholeSum = pList.sumOf { it.sum } val out = PrintWriter(System.out) for(i in 0 until q) { if(s[i] > wholeSum) { out.println(-1) continue } var sum = 0L var sizeSum = 0L for(j in pList.indices) { val p = pList[j] sizeSum += p.size sum += p.sum if(sum == s[i].toLong()) { out.println(sizeSum) break } else if(sum > s[i]) { sizeSum -= p.size sum -= p.sum val tmp = p.cumulativeSum.binarySearch(s[i] - sum) val index = if(tmp < 0) -(tmp + 1) else tmp out.println(sizeSum + index) break } } } out.flush() } data class P( val size: Int, val sum: Long, val cumulativeSum: LongArray, ) fun cumulativeSum(a: List): LongArray { val s = LongArray(a.size + 1) for(i in a.indices) { s[i+1] = s[i] + a[i] } return s }