Find the Playing Note
InterviewTime limit1sMemory limit128 MB
Given note durations that partition a timeline, answer queries asking which note covers a given beat by locating the prefix sum that brackets it.
- Level
Medium4 of 10
- Topics
- Prefix sum, Binary search, Array, Sorting
- Solved
- No attempts yet
Problem
Farmer John is teaching his cows to play a song. The song consists of notes (), and the -th note lasts beats (), so the whole song is at most beats long.
Playing starts at time . Note is played from time up to just before time , note from time up to just before , and in general note occupies the half-open interval .
To keep the cows paying attention, Farmer John asks questions (). Each question gives a time and asks: during the interval from time up to just before time , which note should be playing? Every query satisfies , so exactly one note is being played. Report its -based index.
Input
- Line 1: two space-separated integers and .
- Lines 2 to : line contains the single integer .
- Lines to : line contains the single integer , the time asked by the -th query.
Output
- lines: line contains a single integer, the -based index of the note being played during the -th query's interval.