#include <bits/stdc++.h>
using namespace std;
int n, k;
const int maxn = 2000;
int maxval;
struct Table {
  int index, r;
  bool operator<(const Table &rhs) const { return r < rhs.r; }
} table[maxn];
struct Request {
  int index, c, w;
  bool operator<(const Request &rhs) const { return w < rhs.w; }
} request[maxn];
priority_queue<Request> tt[maxn];
struct Ans {
  int tindex, rindex;
} ans[maxn];
bool cmp(const Request &a, const Request &b) { return a.c < b.c; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int cost, weight;
    scanf("%d%d", &cost, &weight);
    request[i].c = cost;
    request[i].w = weight;
    request[i].index = i;
  }
  sort(request + 1, request + 1 + n, cmp);
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    int r;
    scanf("%d", &r);
    table[i].index = i;
    table[i].r = r;
  }
  int sum = 0;
  int cnt = 0;
  sort(table + 1, table + 1 + k);
  for (int i = 1; i <= n; i++) {
    int t =
        lower_bound(table + 1, table + 1 + k, Table{-1, request[i].c}) - table;
    if (t <= k) tt[t].push(request[i]);
  }
  for (int i = 1; i <= k; i++) {
    if (tt[i].empty()) continue;
    Request res = tt[i].top();
    sum += res.w;
    tt[i].pop();
    ans[cnt].tindex = table[i].index;
    ans[cnt].rindex = res.index;
    while (!tt[i].empty()) {
      tt[i + 1].push(tt[i].top());
      tt[i].pop();
    }
    cnt++;
  }
  printf("%d %d\n", cnt, sum);
  for (int i = 0; i < cnt; i++) {
    printf("%d %d\n", ans[i].rindex, ans[i].tindex);
  }
  return 0;
}
