#include <bits/stdc++.h>

#define TASK "fisher"
using namespace std;
typedef long long ll;
typedef long double ld;
const ll inf = numeric_limits<ll>::max();
const ll mod = 1000000007;
const ld eps = 1e-7;
const ll maxn = 123456;

ll n, m, p;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    if(strcmp(TASK,"")!=0)
    {
        freopen(TASK".in","r",stdin);
        freopen(TASK".out","w",stdout);
    }
#endif
    cin >> n >> m >> p;
    vector<pair<ll, ll> > x(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i].first >> x[i].second;
    }
    vector<pair<ll, pair<ll, ll> > > y(m);
    for (int i = 0; i < m; i++)
    {
        cin >> y[i].first >> y[i].second.first >> y[i].second.second;
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    if (p == 0)
    {
        ll cntx = 0;
        for (int i = 0; i < n; i++) cntx += x[i].second;
        vector<pair<ll, ll> > st;
        for (int i = 0; i < m; i++)st.push_back(make_pair(y[i].second.second, y[i].second.first));
        sort(st.begin(), st.end(), greater<pair<ll, ll>>());
        ll ans = 0;
        for (auto i : st)
        {
            if (cntx >= i.second)
            {
                cntx -= i.second;
                ans += i.second * i.first;
            }
            else
            {
                ans += cntx * i.first;
                cntx = 0;
            }
        }
        cout << ans;
        return 0;
    }
    else
    {
        if (y[m - 1].first < x[0].first)
        {
            ll ans = 0;
            vector<pair<ll, ll> > st;
            for (int i = 0; i < m; i++)st.push_back(make_pair(y[i].second.second, y[i].second.first));
            sort(st.begin(), st.end(), greater<pair<ll, ll>>());
            ll nowcan = 0;
            ll nowpos = 0;
            ll fixedsum = 0;
            for (int i = 0; i < n; i++)
            {
                nowcan += x[i].second;
                ll bad = x[i].first * p;
                while (nowpos < m && nowcan >= st[nowpos].second)
                {
                    fixedsum += st[nowpos].first * st[nowpos].second;
                    nowcan -= st[nowpos].second;
                    nowpos++;
                }
                if (nowpos < m)
                {
                    ans = max(fixedsum - bad + nowcan * st[nowpos].first, ans);
                }
                else
                {
                    ans = max(fixedsum - bad, ans);
                }
            }
            cout << ans;
            return 0;
        }
        else
        {
            ll cntx = 0;
            for (int i = 0; i < n; i++) cntx += x[i].second;
            vector<pair<ll, ll> > vec;
            for (int i = 0; i < m; i++)vec.push_back(make_pair(y[i].second.second, y[i].second.first));
            ll allcnt = 0;
            ll allgood = 0;
            ll ans = 0;
            set<pair<ll, ll> > st;
            for (auto i : vec)
            {
                st.insert(i);
                allcnt += i.second;
                allgood += i.first*st.begin()->second;
                while (!st.empty() && allcnt - st.begin()->second >= cntx)
                {
                    allcnt -= st.begin()->second;
                    allgood -= st.begin()->first*st.begin()->second;
                }
                ans = max(ans,allgood+(cntx-allcnt)*st.begin()->first);
            }
            cout << ans;
            return 0;
        }
    }
    return 0;
}