Song Scores
InterviewTime limit2sMemory limit128 MB
Given cumulative durations of N song scores, answer Q queries asking which score is being sung at a given time using prefix sums and search.
- Level
Easy2 of 10
- Topics
- Prefix sum, Binary search, Simulation
- Solved
- No attempts yet
Problem
Hyunsu is teaching students a song. The song consists of N scores, and the i-th score lasts Bi seconds. The students start singing along with score 1 at time 0. Therefore, they sing score 1 from second 0 through second B1-1, and score 2 from second B1 through second B1+B2-1.
You are given Q times T1, T2, ..., TQ. For each time Ti, output the number of the score the students are singing at that second, in query order.
Input
The first line contains the number of scores N (1 ≤ N ≤ 100) and the number of queries Q (1 ≤ Q ≤ 1,000). Each of the next N lines contains one integer: the duration in seconds of one score, from score 1 through score N. Each duration is an integer no greater than 100. Each of the next Q lines contains one queried time in seconds. Each queried time is also an integer.
Output
Print Q lines. For the 1st through Q-th queries, print the number of the score being sung at the corresponding time.