CF302B.Eugeny and Play List

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Eugeny loves listening to music. He has n songs in his play list. We know that song number i has the duration of t__i minutes. Eugeny listens to each song, perhaps more than once. He listens to song number i c__i times. Eugeny's play list is organized as follows: first song number 1 plays _c_1 times, then song number 2 plays _c_2 times, ..., in the end the song number n plays c__n 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.

尤金尼喜欢听音乐。他的播放列表中有 nn 首歌曲。已知第 ii 首歌曲的时长为 tit_i 分钟。尤金尼会依次收听每首歌曲,可能重复多次。他收听第 ii 首歌曲 cic_i 次。播放列表的组织方式如下:第 1 首歌曲连续播放 c1c_1 次,接着第 2 首歌曲连续播放 c2c_2 次,……,最后第 nn 首歌曲连续播放 cnc_n 次。

尤金尼拿出一张纸,记录下了他喜爱歌曲的 mm 个时刻。现在,对于每个这样的时刻,他想知道当时正在播放的是哪一首歌。“时刻 xx” 的含义是:尤金尼想知道在他收听整个播放列表的过程中,第 xx 分钟正在播放哪一首歌曲。

请帮助尤金尼计算出这些时刻所对应的歌曲编号。

输入格式

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 c__i, t__i (1 ≤ c__i, t__i ≤ 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 _v_1, _v_2, ..., v__m, that describe the moments Eugeny has written out. It is guaranteed that there isn't such moment of time v__i, when the music doesn't play any longer. It is guaranteed that v__i < v__i + 1 (i < m).

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

第一行包含两个整数 nn、mm(1≤n,m≤1051 \leq n, m \leq 10^5)。接下来的 nn 行每行包含一对整数。第 ii 行包含整数 cic_i、tit_i(1≤ci,ti≤1091 \leq c_i, t_i \leq 10^9)——描述播放列表。保证该播放列表的总时长不超过 10910^9!。

下一行包含 mm 个正整数 v1,v2,…,vmv_1, v_2, \dots, v_m,表示 Eugeny 记录下的各个时刻。保证不存在某个时刻 viv_i,使得此时音乐已停止播放。同时保证 vi<vi+1v_i < v_{i+1}(i<mi < m)。

时刻 viv_i 表示 Eugeny 想知道:从开始收听播放列表起第 viv_i 分钟时正在播放哪一首歌曲。

输出格式

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

输出 m 个整数——其中第 i 个数必须等于 Eugeny 开始收听播放列表后第 v__i 分钟正在播放的歌曲编号。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页