#include int main() { long n, q, len = 0; scanf("%ld%ld", &n, &q); long a[100]; for (long i = 0; i < n; i++) { scanf("%ld", &a[i]); len += a[i]; } long c_idx[101], c[101]; c_idx[0] = 0; c[0] = 0; for (long i = 0; i < n; i++) { c_idx[i + 1] = c_idx[i] + a[i]; c[i + 1] = c[i] + a[i] * (a[i] + 1) / 2; } for (long i = 0; i < q; i++) { long s; scanf("%ld", &s); long l_idx = std::lower_bound(c, c + n + 1, s) - c; long l = c_idx[l_idx - 1], r = c_idx[l_idx]; while (r - l > 1) { long mid = (l + r) / 2; long k = std::upper_bound(c_idx, c_idx + n + 1, mid) - c_idx; long d = mid - c_idx[k - 1]; if (c[k - 1] + d * (d + 1) / 2 >= s) { r = mid; } else { l = mid; } } if (r > len) { r = -1; } printf("%ld\n", r); } }