#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for(int i = 0; i < n; i++)
#define sz(a) int(a.size())
#define re return
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll n, m, p, x, k, ans;
vector<pair<ll, pair<ll, int> > > a;
multiset<pll> qq, c1;
int main() {
    iostream::sync_with_stdio(0), cin.tie(0);
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    cin >> n >> m >> p;
    forn (i, n) {
        cin >> x >> k;
        a.push_back({x, {k, 0}});
    }
    forn (i, m) {
        ll cc;
        cin >> x >> k >> cc;
        a.push_back({x, {k, cc}});
    }
    sort(a.begin(), a.end());
    ll cc = 0, sum = 0;
    for (int i = 0; i < sz(a); i++) {
        if (a[i].se.se == 0) {
            cc += a[i].se.fi;
            while (!c1.empty() && cc) {
                ll k = min(c1.rbegin() -> se, cc);
                cc -= k;
                qq.insert(mp(c1.rbegin() -> fi, k));
                pll p = *c1.rbegin();
                c1.erase(c1.find(p));
                sum += p.fi * k;
                p.se -= k;
                if (p.se) c1.insert(p);
            }
            ans = max(ans, sum - p * a[i].fi);
            continue;
        }
        ll pp = a[i].se.fi;
        while (!qq.empty() && qq.begin() -> fi < a[i].se.se && cc < pp) {
            ll k = min(pp - cc, qq.begin() -> se);
            sum -= (qq.begin() -> fi) * k;
            cc += k;
            pll p = *qq.begin();
            qq.erase(qq.find(p));
            p.se -= k;
            if (p.se) qq.insert(p);
        }
        sum += min(cc, pp) * a[i].se.se;
        if (min(cc, pp) > 0) qq.insert(mp(a[i].se.se, min(cc, pp)));
        if (pp > cc) c1.insert(mp(a[i].se.se, pp - cc));
        cc -= min(cc, pp);
        ans = max(ans, sum - p * a[i].fi);
    }
    cout << ans;
    re 0;
}

