您的位置:首页 > 其它

B. Eugeny and Play List

2013-08-15 16:47 295 查看
time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Eugeny loves listening to music. He has n songs in his play list. We know that song number i has
the duration of ti minutes.
Eugeny listens to each song, perhaps more than once. He listens to song number i ci times.
Eugeny's play list is organized as follows: first song number 1 plays c1 times,
then song number 2 plays c2 times, ...,
in the end the song number n plays cn times.

Eugeny took a piece of paper and wrote out m 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 x means that Eugeny wants to know which song was playing during the x-th
minute of his listening to the play list.

Help Eugeny and calculate the required numbers of songs.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 105).
The next n lines contain pairs of integers. The i-th
line contains integers ci, ti(1 ≤ ci, ti ≤ 109) —
the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 109 

.

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

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

Output

Print m integers — the i-th
number must equal the number of the song that was playing during the vi-th
minute after Eugeny started listening to the play list.

Sample test(s)

input
1 2
2 8
1 16


output
1
1


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


output
1
12
2
3
4
4
4
4


解题说明:此题虽然是一道歌曲播放问题,但是实际是判断某个数落在哪个区间段内。mp3中的歌曲播放的时间就是一段段区间,而给出的时刻就是一个数。

#include <iostream>
#include<algorithm>
#include<fstream>
#include<cstdio>
#include<cstring>
using namespace std;

long i,j,k,n,m,a[100002];

int main()
{
scanf("%ld %ld",&n,&m);
for(i=0;i<n;i++)
{
scanf("%ld %ld",&j,&k);
a[i]=j*k;
}
for(i=0,j=0,n=0;i<m;i++)
{
scanf("%ld",&k);
while(n<k)
{
n+=a[j];
j++;
}
printf("%ld\n",j);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: