#include<iostream>
#include<algorithm>
#include<stdio.h>

using namespace std;
struct tri{
    long long y;
    long long b;
    long long c;
};
struct two{
    long long x;
    long long a;
};
bool sortf(tri a, tri b) {
    return a.c > b.c;
}
int main() {
freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    long long n, m, p;
    cin >> n >> m >> p;
    if (p == 0) {
        long long c = 0;
        two x[n];
        tri y[m];
        long long s = 0;
        for (long long i = 0; i < n; i++) {
            cin >> x[i].x >> x[i].a;
            s += x[i].a;
        }
        for (long long i = 0; i < m; i++) {
            cin >> y[i].y >> y[i].b >> y[i].c;
        }
        sort(y, y + m, sortf);
        for (long long i = 0; i < m; i++) {
            //cout << y[i].c << ' ';
            if (s >= y[i].b) {
                c += y[i].c * y[i].b;
                s -= y[i].b;
            } else {
                c += y[i].c * s;
                s = 0;
            }
        }
        cout << c;
    }
}
