题目描述:
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.
输入描述:
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.
输出描述:
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.
题意:
题目意思就是给我们n组样例 和 m组 查询 后面跟随n组样例 每一组样例有一个循环次数和这首歌播放的时间,m组查询v[i]时间 要我们求这v[i]这个时刻在播放第几首歌
思路:
每次计算这首歌结束的时刻是什么,接着压入到vector 数组里面然后采用lower_bound取出下表+1的位置就是答案 (lower_bound 是查找不小于当前下标所对应值的第一个元素位置在哪)
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,k;
vector<int>v;
int main(){
cin>>n>>m;
int ans=0;
for(int i=0;i<n;i++){
cin>>a>>b;
ans+=a*b;
v.push_back(ans);
}
for(int i=0;i<m;i++){
cin>>k;
cout<<lower_bound(v.begin(),v.end(),k)-v.begin()+1<<" ";
}
cout<<endl;
return 0;
}