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

using namespace std;

struct f {
    int x;
    int num;
};

struct s {
    int x;
    int num;
    int cost;
};

vector <f> fish;
vector <s> shop;
vector <pair <int, int> > c;

int main() {
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    int n, m, p, x, num, cost; long long fish_num = 0, money = 0;
    f cur;
    s cur2;
    cin >> n >> m >> p;
    for (int i = 0; i < n; i++) {
        cin >> cur.x >> cur.num;
        fish_num += cur.num;
        fish.push_back(cur);
    }
    for (int i = 0; i < m; i++) {
        cin >> cur2.x >> cur2.num >> cur2.cost;
        shop.push_back(cur2);
    }
    //cout << fish_num << endl;
    if (p == 0) {
        for (int i = 0; i < m; i++) {
            c.push_back(make_pair(shop[i].cost, shop[i].num));
        }
        sort(c.begin(), c.end());
       // for (int i = 0; i < c.size(); i++) {
            //cout << c[i].first << " " << c[i].second << endl;
       // }
        int i = m - 1;
        while (i >= 0 && fish_num > 0) {
            if (fish_num >= c[i].second) {
                fish_num -= c[i].second;
                //cout << money << endl;
                money += (c[i].second * c[i].first);
                //cout << money << endl;
            }
            else {
                money += (fish_num * c[i].first);
                fish_num = 0;
            }
            i -= 1;
        }
        cout << money;
    }
    fclose(stdin);
    fclose(stdout);
}
