~/algor $ cat problems/qidiruv-yigindi-qachon-yetadi
When does the sum reach x?
Easy
1000 ms
128 MB
33%
An array $a$ of $n$ positive integers and $q$ queries are given. Each query gives a positive integer $x$: find the smallest $k$ such that $a_{1} + a_{2} + \dots + a_{k} \ge x$. If even the sum of the whole array is less than $x$, print $-1$.
Input
The first line contains two positive integers: $n$ and $q$.
The second line contains $n$ positive integers $a_{i}$.
Each of the next $q$ lines contains one positive integer $x$.
Output
For each query on a separate line: $k$ or $-1$.
Note
$1 \le n, q \le 10^{5}$
$1 \le a_{i} \le 10^{9}$
$1 \le x \le 10^{18}$
Examples
Input #1
5 3 2 5 1 4 3 7 8 16
Output #1
2 3 -1
Input #2
1 2 4 4 5
Output #2
1 -1