uses
  Math;

type
  cond = record
    power, cost: longint;
  end;

var
  b: array[1..200000] of cond;
  a, best: array[1..200000] of longint;
  n, m, i, l, r, mid: longint;
  c: cond;
  ans: int64;

function Less(c1, c2: cond): boolean;
begin
  if (c1.power < c2.power) then Less := true
  else if (c1.power = c2.power) and (c1.cost < c2.cost) then Less := true
  else Less := false;
end;

procedure Swap(var a, b: cond);
var
  c: cond;
begin
  c := a;
  a := b;
  b := c;
end;

procedure Sort(l, r: Longint);
var
  i, j: longint;
  x: cond;
begin
  i := l; j := r; x := b[i + random(j - i + 1)];
  repeat
    while Less(b[i], x) do inc(i);
    while Less(x, b[j]) do dec(j);
    if i <= j then begin
      swap(b[i], b[j]);
      inc(i); dec(j);
    end;
  until i > j;
  if i < r then Sort(i, r);
  if j > l then Sort(l, j);
end;

begin
  Assign(input, 'cond.in');
  Assign(output, 'cond.out');
  Reset(input);
  Rewrite(output);
  read(n);
  for i := 1 to n do
    read(a[i]);
  read(m);
  for i := 1 to m do
    read(b[i].power, b[i].cost);
  
  Sort(1, m);
  best[m] := b[m].cost;
  for i := m - 1 downto 1 do 
  begin
    best[i] := Min(best[i + 1], b[i].cost);
  end;
  
  ans := 0;
  for i := 1 to n do 
  begin
    l := 0;
    r := m + 1;
    c.power := a[i] - 1;
    c.cost := 2000000000;
    while (l + 1 < r) do 
    begin
      mid := (l + r) div 2;
      if (Less(c, b[mid])) then r := mid else l := mid;
    end;
    ans := ans + best[r];
  end;
  writeln(ans);
end.