#include <bits/stdc++.h>

using namespace std;

long long mnx = 1e9, mny = 1e9, mxx = 1, mxy = 1;
long long x[500000], y[500000], a[500000], b[500000], c[500000];
long long w = 0;
vector<pair<long long, long long> > v;

int main()
{
    ifstream cin("fisher.in");
    ofstream cout("fisher.out");
    int n, m, p;
    cin >> n >> m >> p;
    for (int i = 0; i < n; i++){
        cin >> x[i] >> a[i];
        mnx = min(mnx, x[i]);
        mxx = max(mxx, x[i]);
        w += a[i];
    }

    for (int i = 0; i < m; i++){
        cin >> y[i] >> b[i] >> c[i];
        mny = min(mny, y[i]);
        mxy = max(mxy, y[i]);
        v.push_back({c[i], b[i]});
    }

    if (p == 0){
        long long ans = 0;
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        for (int i = 0; i < m; i++){
            ans += min(w, v[i].second) * v[i].first;
            w -= min(w, v[i].second);
        }

        cout << ans << '\n';
        return 0;
    }
    if (mnx > mxy){
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        long long now = 0;
        long long ans = 0;
        int l = 0;
        for (int i = 0; i < n; i++){
            while (l < m && a[i] > 0){
                long long per = min(a[i], v[l].second);
                now += per * v[l].first;
                v[l].second -= per;
                if (v[l].second == 0)
                    l++;
                a[i] -= per;
            }
            ans = max(ans, now - x[i] * p);
        }

        cout << ans;
        return 0;
    }

    if (mny > mxx){
        long long now = 0;
        long long ans = 0;
        map<long long, long long> ma;
        for (int i = 0; i < m; i++){
            long long per = min(v[i].second, w);
            ma[v[i].first] += per;
            now += per * v[i].first;
            w -= per;
            v[i].second -= per;

            while (ma.begin()->first < v[i].first && v[i].second > 0){
                now = now - min(v[i].second, ma.begin()->second) * ma.begin()->first + min(v[i].second, ma.begin()->second) + v[i].first;

                ma[v[i].second] += min(v[i].second, ma.begin()->second);
                ma.begin()->second -= min(v[i].second, ma.begin()->second);
                if (ma.begin()->second == 0)
                    ma.erase(ma.begin()->first);
            }

            ans = max(ans, now - y[i] * p);
        }

        cout << ans << '\n';
    }
    return 0;
}
