local mfl = math.floor local function comp(a, b) return a < b end local function lower_bound(ary, x) local num = #ary if num == 0 then return 1 end if not comp(ary[1], x) then return 1 end if comp(ary[num], x) then return num + 1 end local min, max = 1, num while 1 < max - min do local mid = mfl((min + max) / 2) if comp(ary[mid], x) then min = mid else max = mid end end return max end local n, q = io.read("*n", "*n") local a = {} for i = 1, n do a[i] = io.read("*n") end local b = {} local f = {} for i = 1, n do for j = 1, i do table.insert(b, a[j]) table.insert(f, i) end end local bsum = {b[1]} for i = 2, #b do bsum[i] = bsum[i - 1] + b[i] end for iq = 1, q do local z = io.read("*n") local lb = lower_bound(bsum, z) if #bsum < lb then print(-1) else -- print(f[lb]) print(lb) end end