← Home
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
mt19937 rnd(time(0));
const int N = 2e5 + 10;
int n, m, ans[N];
struct node {
    int c, q;
    bool operator<(const node &x) const {
        return q != x.q ? q > x.q : c < x.c;
    }
} a[N];
namespace FHQ {
#define lc t[rt].ls
#define rc t[rt].rs
    struct TREE {
        int ls, rs, key, rnd, s, tk, ts;
    } t[N];
    int idx, root, x, y, z;
    void modify_k(int rt, int v) {
        t[rt].key += v, t[rt].tk += v;
    }
    void modify_s(int rt, int v) {
        t[rt].s += v, t[rt].ts += v;
    }
    void push_down(int rt) {
        if (lc)
            modify_k(lc, t[rt].tk), modify_s(lc, t[rt].ts);
        if (rc)
            modify_k(rc, t[rt].tk), modify_s(rc, t[rt].ts);
        t[rt].tk = t[rt].ts = 0;
    }
    void split(int rt, int v, int &l, int &r) {
        if (!rt) {
            l = r = 0;
            return;
        }
        push_down(rt);
        if (t[rt].key <= v) {
            l = rt;
            split(rc, v, rc, r);
        } else {
            r = rt;
            split(lc, v, l, lc);
        }
    }
    int merge(int r1, int r2) {
        if (!r1 or !r2)
            return r1 | r2;
        push_down(r1), push_down(r2);
        if (t[r1].rnd > t[r2].rnd) {
            t[r1].rs = merge(t[r1].rs, r2);
            return r1;
        } else {
            t[r2].ls = merge(r1, t[r2].ls);
            return r2;
        }
    }
    int newnode(int v) {
        t[++idx] = {0, 0, v, (int)rnd(), 0, 0, 0};
        return idx;
    }
    void insert(int &rt, int idx) {
        split(rt, t[idx].key, x, y);
        rt = merge(merge(x, idx), y);
    }
    void dfs(int rt, int &x, int v) {
        if (!rt)
            return;
        push_down(rt);
        if (lc)
            dfs(lc, x, v);
        if (rc)
            dfs(rc, x, v);
        lc = rc = 0;
        t[rt].key += v;
        t[rt].s++;
        insert(x, rt);
    }
    void getans(int rt) {
        push_down(rt);
        if (lc)
            getans(lc);
        if (rc)
            getans(rc);
        ans[rt] = t[rt].s;
    }
}
using namespace FHQ;
signed main() {
    IOS;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].c >> a[i].q;
    cin >> m;
    for (int i = 1, x; i <= m; i++) {
        cin >> x;
        insert(root, newnode(x));
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        int t1, t2, t3;
        split(root, a[i].c - 1, t1, t2);
        split(t2, a[i].c * 2 - 1, t2, t3);
        modify_k(t3, -a[i].c);
        modify_s(t3, 1);
        dfs(t2, t1, -a[i].c);
        root = merge(t1, t3);
    }
    getans(root);
    for (int i = 1; i <= m; i++)
        cout << ans[i] << " ";
    return 0;
}