#include <bits/stdc++.h>

#define vec vector
#define forn(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
#define YY second
#define XX first
#define vec vector
#define pb push_back
#define ll long long
#define all(a) a.begin(), a.end()

using namespace std;

const bool is_testing = false;

ll n, m, p;
vec < pair<ll, ll> > a;
vec < pair< pair<ll, ll>, ll > > b;

int main()
{
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    if (is_testing)
    {
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    }
    cin >> n >> m >> p;
    a.resize(n);
    b.resize(m);
    forn(i, n)
        cin >> a[i].XX >> a[i].YY;
    forn(i, m)
        cin >> b[i].YY >> b[i].XX.YY >> b[i].XX.XX;if (p == 0)
    {
        ll k1 = 0, ans = 0;
        forn(i, n)
            k1 += (ll)a[i].YY;
        sort(all(b));
        reverse(all(b));
        forn(i, m)
        {
            if (k1 >= b[i].XX.YY)
            {
                ans += (ll)b[i].XX.YY * (ll)b[i].XX.XX;
                k1 -= b[i].XX.YY;
            }
            else
            {
                ans += (ll)b[i].XX.XX * (ll)k1;
                k1 = 0;
                break;
            }
        }

        cout << ans;
        exit(0);
    }
    ll k1 = 0;
    ll sum = 0;
    ll ans = 0;
    forn(i, n)
        k1 += (ll)a[i].YY;
    multiset < pair<ll, pair<ll, ll> > > se2;
    multiset < pair<ll, ll> > se1;
    forn(i, m)
    {
        se2.insert( mp(b[i].XX.XX, mp(0, b[i].XX.YY) ) );
        while(k1 > 0 && se2.size() > 0)
        {
            pair<ll, pair<ll, ll> > t = *(--se2.end());
            se2.erase(se2.find(t));
            if (t.YY.YY - t.YY.XX > k1)
            {
                t.YY.XX += k1;
                sum += k1 * t.XX;
                k1 = 0;
                ans = max(ans, sum - p * b[i].YY);
                se2.insert(t);
            }
            else
            {
                ll d = t.YY.YY - t.YY.XX;
                sum += d * t.XX;
                k1 -= d;
                ans = max(ans, sum - p * b[i].YY);
                se1.insert( mp(t.XX, t.YY.YY) );
            }
        }
        while(true)
        {
            if (se2.size() == 0)
                break;
            pair<ll, ll> t1 = *(--se1.end());
            pair<ll, pair<ll, ll> > t2 = *(--se2.end());
            if (t1.XX < t2.XX)
            {
                se1.erase(se1.find(t1));
                se2.erase(se2.find(t2));
                if (t1.YY < t2.YY.YY - t2.YY.XX)
                {
                    t2.YY.XX += t1.YY;
                    sum -= t1.XX * t1.YY;
                    sum += t2.XX * t1.YY;
                    ans = max(ans, sum - p * b[i].YY);
                    se2.insert(t2);
                }
                else
                {
                    ll d = t2.YY.YY - t2.YY.XX;
                    t1.YY -= d;
                    sum -= d * t1.XX;
                    sum += d * t2.XX;
                    ans = max(ans, sum - p * b[i].YY);
                    if (t1.YY > 0)
                        se1.insert(t1);
                    se1.insert( mp(t2.XX, t2.YY.YY) );
                }
            }
            else
                break;
        }
        //cout << ans << endl;
    }
    cout << ans;
}
