Editorial for Goat II


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: kahootist

Editorial

n, q = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = [0] * n
c[0] = a[0]

for i in range(1, n):
    c[i] = c[i-1] + a[i]

for query in b:

    l = 0
    r = n
    while l < r:
        m = (l + r) // 2
        if c[m] > query:
            r = m
        else:
            l = m + 1

    print(r, end=" ")

Comments

There are no comments at the moment.