import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class cond_ak {

    static class Cond implements Comparable<Cond> {
        int cost;
        int power;

        Cond(int cost, int power) {
            this.cost = cost;
            this.power = power;
        }

        @Override
        public int compareTo(Cond c) {
            if (power != c.power) {
                return power - c.power;
            }
            return cost - c.cost;
        }
    }

    void solve() throws IOException {
        int n = in.nextInt();
        int[] classes = new int[n];
        for (int i = 0; i < n; i++) {
            classes[i] = in.nextInt();
        }
        int m = in.nextInt();
        Cond[] conditioners = new Cond[m];
        for (int i = 0; i < m; i++) {
            int power = in.nextInt();
            int cost = in.nextInt();
            conditioners[i] = new Cond(cost, power);
        }
        Arrays.sort(classes);
        Arrays.sort(conditioners);
        int j = conditioners.length - 1;
        Cond best = conditioners[conditioners.length - 1];
        long ans = 0;
        for (int i = classes.length - 1; i >= 0; i--) {
            while (j >= 0 && conditioners[j].power >= classes[i]) {
                if (conditioners[j].cost < best.cost) {
                    best = conditioners[j];
                }
                j--;
            }
            ans += best.cost;
        }
        out.println(ans);
    }

    static MyScanner in;
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        in = new MyScanner(new FileReader("cond.in"));
        out = new PrintWriter("cond.out");
        new cond_ak().solve();
        out.close();
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(Reader r) {
            br = new BufferedReader(r);
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
    }
}
