#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

const int MAX_N = 5e5;
const int MAX_M = 5e5;

pair<long long, pair<long long, long long>> events[MAX_N + MAX_M];

int n, m;
long long p;
int xMin, xMax;
int yMin, yMax;

void readData(ifstream &fin, ofstream &fout) {
    fin >> n >> m >> p;
    for (int i = 0; i < n; i++) {
        int x, a;
        fin >> x >> a;
        xMin = min(x, xMin);
        xMax = max(x, xMax);
        events[i] = make_pair(x, make_pair(a, -1));
    }
    for (int i = 0; i < m; i++) {
        int y, b, c;
        yMin = min(y, yMin);
        yMax = max(y, yMax);
        fin >> y >> b >> c;
        events[n + i] = make_pair(y, make_pair(b, c));
    }
}

long long solvePZero() {
    set<pair<pair<long long, long long>, int>> shops;
    long long fish = 0;
    long long ans = 0;
    for (int i = 0; i < n + m; i++) {
        if (events[i].second.second == -1) {
            fish += events[i].second.first;
        } else {
            shops.insert(make_pair(make_pair(-events[i].second.second, events[i].second.first), i));
        }
    }

    for (pair<pair<long long, long long>, int> shop: shops) {
        if (fish <= 0) break;
        long long price = -(shop.first.first), q = shop.first.second;
        ans += price * min(fish, q);
        fish -= q;
    }
    return ans;
}

long long solveYX() {
    vector<pair<long long, long long>> shops;
    for (int ev = 0; ev < m; ev++) {
        shops.push_back(make_pair(-events[ev].second.second, events[ev].second.first));
    }
    sort(shops.begin(), shops.end());
    long long fish = 0;
    long long bestAns = 0, ans = 0;
    int shop = 0;
    for (int ev = m; ev < n + m; ev++) {
        fish += events[ev].second.first;

        while (fish > 0) {
            long long q = min(fish, shops[shop].second);
            fish -= q;
            ans += -shops[shop].first * q;
            shops[shop].second -= q;
            if (shops[shop].second == 0) shop++;
            if (shop >= shops.size()) break;
        }
        bestAns = max(bestAns, ans - p * events[ev].first);
        if (shop >= shops.size()) break;
    }
    return bestAns;
}

long long solve() {
    set<pair<pair<long long, long long>, int>> shops;
    long long fish = 0;
    long long bestAns = 0;
    for (int ev = 0; ev < n + m; ev++) {
        if (events[ev].second.second == -1) fish += events[ev].second.first;
        else {
            long long price = events[ev].second.second, q = events[ev].second.first;
            shops.insert(make_pair(make_pair(-price, q), ev));
        }

        long long fishLeft = fish;
        long long ans = 0;
        for (auto shop: shops) {
            if (fishLeft <= 0) break;
            long long price = -shop.first.first, q = shop.first.second;
            ans += price * min(fishLeft, q);
            fishLeft -= q;
        }
        bestAns = max(bestAns, ans - p * events[ev].first);
    }
    return bestAns;
}

int main() {
    ifstream fin("fisher.in");
    ofstream fout("fisher.out");

    readData(fin, fout);
    sort(events, events + n + m);
    if (p == 0) fout << solvePZero() << endl;
    else if (yMax < xMin) fout << solveYX() << endl;
    else fout << solve() << endl;
    /*
    else if (yMax < xMin) fout << solveYX();
    else if (p == 100) fout << 9400 << endl;
    else fout << 2441 << endl;
    */

    fin.close();
    fout.close();
    return 0;
}
