CF302B.Eugeny and Play List

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Eugeny loves listening to music. He has nn songs in his play list. We know that song number ii has the duration of tit_{i} minutes. Eugeny listens to each song, perhaps more than once. He listens to song number ii cic_{i} times. Eugeny's play list is organized as follows: first song number 11 plays c1c_{1} times, then song number 22 plays c2c_{2} times, ...... , in the end the song number nn plays cnc_{n} times.

Eugeny took a piece of paper and wrote out mm moments of time when he liked a song. Now for each such moment he wants to know the number of the song that played at that moment. The moment xx means that Eugeny wants to know which song was playing during the xx -th minute of his listening to the play list.

Help Eugeny and calculate the required numbers of songs.

输入格式

The first line contains two integers nn , mm (1<=n,m<=105)(1<=n,m<=10^{5}) . The next nn lines contain pairs of integers. The ii -th line contains integers ci,tic_{i},t_{i} (1<=ci,ti<=109)(1<=c_{i},t_{i}<=10^{9}) — the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 10910^{9} .

The next line contains mm positive integers v1,v2,...,vmv_{1},v_{2},...,v_{m} , that describe the moments Eugeny has written out. It is guaranteed that there isn't such moment of time viv_{i} , when the music doesn't play any longer. It is guaranteed that v_{i}<v_{i+1} (i<m) .

The moment of time viv_{i} means that Eugeny wants to know which song was playing during the viv_{i} -th munite from the start of listening to the playlist.

输出格式

Print mm integers — the ii -th number must equal the number of the song that was playing during the viv_{i} -th minute after Eugeny started listening to the play list.

输入输出样例

  • 输入#1

    1 2
    2 8
    1 16
    

    输出#1

    1
    1
    
  • 输入#2

    4 9
    1 2
    2 1
    1 1
    2 2
    1 2 3 4 5 6 7 8 9
    

    输出#2

    1
    1
    2
    2
    3
    4
    4
    4
    4
    
首页