// Codeforces Round #182 (Div. 2) B Eugeny and Play List
import java.io.*;
import java.math.*;
import java.util.*;
//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;
private static void solve() throws IOException
{
int N = in.nextInt();
int M = in.nextInt();
long[] c = new long[N + 1];
long[] t = new long[N + 1];
for (int i = 1; i <= N; i++) {
c[i] = in.nextLong();
t[i] = in.nextLong();
}
long[] tstart = new long[N + 1];
long[] tend = new long[N + 1];
tstart[1] = 1;
tend[1] = 1 + (c[1] * t[1]) - 1;
for (int i = 2; i <= N; i++) {
tstart[i] = tend[i - 1] + 1;
tend[i] = tstart[i] + (c[i] * t[i]) - 1;
}
int[] v = new int[M + 1];
in.nextLine();
String ln = in.nextLine();
String[] s = ln.split(" ");
for (int i = 1; i <= M; i++) {
v[i] = Integer.valueOf(s[i - 1]);
}
StringBuilder sb = new StringBuilder("");
for (int i = 1; i <= M; i++) {
int L = 1;
int R = N;
int tm = v[i];
while (L <= R) {
int idx = (L + R) / 2;
if (tm >= tstart[idx] && tm <= tend[idx]) {
sb.append(idx);
sb.append("\n");
break;
}
if (tm < tstart[idx]) {
R = idx - 1;
}
else {
L = idx + 1;
}
}
}
out.println(sb.toString());
}
public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
LOCAL_TEST = (cname.equals("ALPHA530"));
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
public String nextLine() throws IOException {
return inp.nextLine();
}
}
}
No comments:
Post a Comment