#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n, m, p, x[500006], y[500006], a[500006], b[500005], c[500005];

set <pair <ll, ll> > ch, ch2;

int main() {
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    cin >> n >> m >> p;
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> a[i];
    }
    for(int i = 0; i < m; i++) {
        cin >> y[i] >> b[i] >> c[i];
    }
    int id1 = 0, id2 = 0;
    ll ans = 0;
    ll ul = 0;
    for(int i = 0; i < m + n; i++) {
        if (id1 >= n && id2 >= m) {
            break;
        }
        if (id2 >= m || x[id1] < y[id2]) {
            ll ans2 = -p*x[id1];
            ul += a[id1];
            ch2.clear();
            ll ul2 = ul;
            while(ul2 != 0) {
                if (ch.empty()) {
                    break;
                }
                pair <ll, ll> ar;
                ar.first = -((ch.begin())->first);
                ar.second = (ch.begin())->second;
                ans2 += (min(ul2, ar.second)*ar.first);
                ul2 -= min(ul2, ar.second);
                ch.erase(ch.begin());
                ar.first *= (-1);
                ch2.insert(ar);
            }
            ans = max(ans, ans2);
            ch = ch2;
            id1++;
            continue;
        }
        if (id1 >= n || x[id1] > y[id2]) {
            ll ans2 = -p*y[id2];
            ch.insert(make_pair(-c[id2], b[id2]));
            ch2.clear();
            ll ul2 = ul;
            if (ul2 == 0) {
                ch2 = ch;
            }
            while(ul2 != 0) {
                if (ch.empty()) {
                    break;
                }
                pair <ll, ll> ar;
                ar.first = -((ch.begin())->first);
                ar.second = (ch.begin())->second;
                ans2 += (min(ul2, ar.second)*ar.first);
                ul2 -= min(ul2, ar.second);
                ch.erase(ch.begin());
                ar.first *= (-1);
                ch2.insert(ar);
            }
            ans = max(ans, ans2);
            ch = ch2;
            id2++;
            continue;
        }
        if (x[id1] == y[id2]) {
            ll ans2 = -p*y[id2];
            ul += a[id1];
            ch.insert(make_pair(-c[id2], b[id2]));
            ch2.clear();
            ll ul2 = ul;
            if (ul2 == 0) {
                ch2 = ch;
            }
            while(ul2 != 0) {
                if (ch.empty()) {
                    break;
                }
                pair <ll, ll> ar;
                ar.first = -((ch.begin())->first);
                ar.second = (ch.begin())->second;
                ans2 += (min(ul2, ar.second)*ar.first);
                ul2 -= min(ul2, ar.second);
                ch.erase(ch.begin());
                ar.first *= (-1);
                ch2.insert(ar);
            }
            ans = max(ans, ans2);
            ch = ch2;
            id2++;
            id1++;
            continue;
        }
    }
    cout << ans;
    return 0;
}
