B. Eugeny and Play List

B. Eugeny and Play List
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 nm (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
1
2
2
3
4
4
4
4
这题还是比较简单,就是用一般的思路会超时,下面就说下题意吧,估计有些人和我一样看个题目都要半天,谁叫俺们英语差啊.......
题目大概意思是: Eugeny 喜欢听歌,他听的歌有些不只听一次,他听的方式是这样的,第一首歌听 c1而且每首歌听t1分钟,第二首歌听 c2而且每首歌听t2分钟....第N首歌听 cn而且每首歌听tn分钟,输入n,m下面跟着n行,每行有两个整数ci, ti意思前面说了然后下面一行有m个整数每个整数代表一个时刻,问在每个时刻,Eugeny在听第几首歌并且输出它.
估计题目懂了,你们也应该能敲出代码来,下面废话不多说,直接看代码吧
代码:
#include<iostream>
const int MAX=100001;
int x[MAX];
int y[MAX];
__int32 z[MAX]={0};//初始化0
using namespace std;
int main()
{
__int32 n,m,i,j,a,p;
cin>>n>>m;
p=1;
cin>>x[1]>>y[1];
z[1]=x[1]*y[1];
for(i=2;i<=n;i++)
{
cin>>x[i]>>y[i];
z[i]+=x[i]*y[i]+z[i-1];
}
for(j=1;j<=m;j++)
{
cin>>a;
while(a>z[p])
p++;
cout<<p<<endl;
}
return 0;
}//如果有问题,或有什么疑惑,可以在评论中提出,小子我看到一定尽力解答
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
- cmder: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://github.com/cmderdev/cmder/issues/603 - ConEmu: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://conemu.github.io/en/ClearScreen.html - Windows Terminal: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://docs.microsoft.com/en-us/windows/terminal/how-to/scrolling - PowerShell: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_editing?view=powershell-7.1#clearing-text - Git Bash: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://git-scm.com/book/en/v2/Git-Basics-Undoing-Things - Babun: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://babun.github.io/faq.html#how-do-i-clear-the-terminal - Cygwin: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://cygwin.com/cygwin-ug-net/using-terminal.html#using-terminal-clear - MobaXterm: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://mobaxterm.mobatek.net/documentation.html#4_1 - Terminus: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://github.com/Eugeny/terminus/issues/157 - Fluent Terminal: 支持一键删除选中内容操作,具体操作方式为选中内容后按下 "Delete" 键或 "Backspace" 键即可删除。官方说明:https://github.com/felixse/FluentTerminal/issues/46
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值