#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
    ifstream in("cond.in");
    int n;
    in >> n;
    vector<int> classes(n);
    for (int i = 0; i < n; i++) {
        in >> classes[i];
    }
    int m;
    in >> m;
    vector<pair<int, int> > conditioners(m);
    for (int i = 0; i < m; i++) {
        in >> conditioners[i].first >> conditioners[i].second;
    }
    sort(classes.begin(), classes.end());
    sort(conditioners.begin(), conditioners.end());
    int j = conditioners.size() - 1;
    int best = conditioners[j].second;
    long long ans = 0;
    for (int i = classes.size() - 1; i >= 0; i--) {
        while (j >= 0 && conditioners[j].first >= classes[i]) {
            if (conditioners[j].second < best) {
                best = conditioners[j].second;
            }
            j--;
        }
        ans += best;
    }
    ofstream("cond.out") << ans << "\n";
}

