#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
struct prioritynode {
  int val;
  int id;
  int pid;
  prioritynode(int _val = 0, int _id = 0, int _pid = 0)
      : val(_val), id(_id), pid(_pid) {}
  bool operator<(const prioritynode &x) const { return this->val > x.val; }
};
priority_queue<prioritynode> q;
struct node {
  int id, c, p;
  node(int _id = 0, int _c = 0, int _p = 0) : id(_id), c(_c), p(_p) {}
  bool operator<(const node &x) const { return this->c > x.c; }
} a[MAXN];
struct rnode {
  int r, id;
  rnode(int _r = 0, int _id = 0) : r(_r), id(_id) {}
  bool operator<(const rnode &x) const { return this->r > x.r; }
} r[MAXN];
int n, m, ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &a[i].c, &a[i].p);
    a[i].id = i;
  }
  sort(a + 1, a + 1 + n);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &r[i].r);
    r[i].id = i;
  }
  sort(r + 1, r + 1 + m);
  int pin = 1;
  for (int i = 1; i <= n; ++i) {
    if (r[pin].r >= a[i].c) {
      ans += a[i].p;
      q.push(prioritynode(a[i].p, a[i].id, r[pin].id));
      ++pin;
    } else {
      if (!q.empty() && a[i].p > q.top().val) {
        ans -= q.top().val;
        int pid = q.top().pid;
        q.pop();
        ans += a[i].p;
        q.push(prioritynode(a[i].p, a[i].id, pid));
      }
    }
  }
  printf("%d %d\n", q.size(), ans);
  while (!q.empty()) {
    printf("%d %d\n", q.top().id, q.top().pid);
    q.pop();
  }
  return 0;
}
