import java.util.*;
import java.io.*;

public class cond_sp implements Runnable {
	public static void main(String[] args) {
		new Thread(new cond_sp()).start();
	}

	@Override
	public void run() {
		try {
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	private final String FNAME = "cond";
	
	class Cond implements Comparable<Cond> {
		int b, c;
		int minc;
		
		Cond() {
			b = nextInt();
			c = nextInt();
		}

		@Override
		public int compareTo(Cond o) {
			return b - o.b;
		}
	}

	void solve() {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		int m = nextInt();
		Cond[] c = new Cond[m];
		for (int i = 0; i < m; i++) {
			c[i] = new Cond();
		}
		Arrays.sort(a);
		Arrays.sort(c);
		c[m - 1].minc = c[m - 1].c;
		for (int i = m - 2; i >= 0; i--) {
			c[i].minc = Math.min(c[i].c, c[i + 1].minc);
		}
		int j = 0;
		long ans = 0;
		for (int i = 0; i < n; i++) {
			while (c[j].b < a[i]) {
				j++;
			}
			ans += c[j].minc;
		}
		out.println(ans);
	}
}