B题地址:http://codeforces.com/contest/302/problem/B
注:好坑啊二分啊。
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define N 100005
int a[N];
int main()
{
int n,m;
int i,j,k;
while(cin>>n>>m)
{
int st=0;
int num1,num2;
int mid;
a[0]=0;
for(i=1;i<=n;i++)
{
cin>>num1>>num2;
a[i]=st+num1*num2;
st=a[i];
}
while(m--)
{
cin>>num1;
int top=n;
int bottom=0;
int mid;
while(bottom<=top)
{
mid=(top+bottom)/2;
if(a[mid]<num1&&a[mid+1]>=num1)
{
cout<<mid+1<<endl;
break;
}
if(a[mid]<num1) bottom=mid+1;
else top=mid-1;
}
}
}
return 0;
}