#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, ll> > > a;
map<ll, ll> 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;
    scanf("%lld%lld%lld", &n, &m, &p);
    forn (i, n) {
        scanf("%lld%lld", &x, &k);
        //cin >> x >> k;
        a.push_back({x, {k, 0}});
    }
    forn (i, m) {
        ll cc;
        scanf("%lld%lld%lld", &x, &k, &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) {
                pll p = *c1.rbegin();
                ll k = min(p.se, cc);
                cc -= k;
                qq[p.fi] += k;
                c1[p.fi] -= k;
                if (c1[p.fi] == 0) {
                    c1.erase(c1.find(p.fi));
                }
                sum += p.fi * k;
            }
            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) {
            pll p = *qq.begin();
            ll k = min(pp - cc, p.se);
            sum -= p.fi * k;
            cc += k;
            qq[p.fi] -= k;
            if (qq[p.fi] == 0)
                qq.erase(qq.find(p.fi));
            c1[p.fi] += k;
        }
        sum += min(cc, pp) * a[i].se.se;
        if (min(cc, pp) > 0) qq[a[i].se.se] += min(cc, pp);
        if (pp > cc) c1[a[i].se.se] += pp - cc;
        cc -= min(cc, pp);
        ans = max(ans, sum - p * a[i].fi);
    }
    //re 0;
    printf("%lld", ans);
    //cout << ans;
    re 0;
}
