Editorial for Goat II


Author:kahootist

Editorial

Code 1
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=" ")

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.