BOJ - 16510 - Predictable Queue

Updated:

import sys

def upper_bound(xs, target):
	low, high = 0, len(xs) - 1
	while low <= high:
		mid = (low + high) // 2
		if xs[mid] > target:
			high = mid - 1
		else:
			low = mid + 1
	return low

def solution():
    N, M = map(int, sys.stdin.readline().split())
    arr = list(map(int, sys.stdin.readline().split()))
    for i in range(1, N):
        arr[i] = arr[i] + arr[i-1]

    for _ in range(M):
        T = int(sys.stdin.readline())
        print(upper_bound(arr, T))

solution()

https://www.acmicpc.net/problem/16510

Categories:

Updated:

Leave a comment