#include <iostream>
#include <stdio.h>
#include <set>
#include <vector>

using namespace std;

vector<pair<long long, long long> > vn;
vector<pair<long long, pair<long long, long long> > > vm;
multiset<pair<long long, long long> > s;

signed main()
{
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    long long n, m, p, res = 0, allfish = 0, flag1 = 1;
    cin >> n >> m >> p;
    vn.resize(n);
    vm.resize(m);
    for (long long i = 0; i < n; ++i) {
        long long t1, t2;
        cin >> t1 >> t2;
        vn[i] = make_pair(t1, t2);
        allfish += t2;
    }
    for (long long i = 0; i < m; ++i) {
        long long t1, t2, t3;
        cin >> t1 >> t2 >> t3;
        vm[i] = make_pair(t1, make_pair(t2, t3));
    }
    /*long long ln = 0, lm = 0, cor = 0, top = 0, fish = 0, solve = 0;
    while (ln < vn.size() && lm < vm.size()) {
        if (lm == vm.size() || vm[lm].first >= vn[ln].first) {

        }
    }*/
    if (p == 0) {
        for (long long i = 0; i < m; ++i) {
            s.insert(make_pair(vm[i].second.second, vm[i].second.first));
        }
        while (s.size() > 0 && allfish > 0) {
            auto t1 = s.end();
            --t1;
            auto p1 = (*t1);
            s.erase(t1);
            if (allfish > p1.second) {
                res += p1.second * p1.first;
                allfish -= p1.second;
            }
            else {
                res += p1.first * allfish;
                allfish = 0;
            }
        }
        cout << res << endl;
        return 0;
    }
    //cout << vm[vm.size() - 1].first << " " << vn[0].first << endl;
    //2134612358742793647921634721346891236419827364761237461276498273948612956368469821639846129863766666666666666666666666666634534534534534
    if (vm[vm.size() - 1].first < vn[0].first) {

        for (long long i = 0; i < m; ++i) {
            s.insert(make_pair(vm[i].second.second, vm[i].second.first));
        }
        long long nowres = 0, nowfish = 0;
        for (long long i = 0; i < n; ++i) {
            if (i == 0) {
                nowres -= p * vn[0].first;
            }
            else {
                nowres -= p * (vn[i].first - vn[i - 1].first);
            }
            nowfish += vn[i].second;
            //cout << nowfish << " " << nowres << " / ";
            while (s.size() > 0 && nowfish > 0) {
                auto t1 = s.end();
                --t1;
                auto p1 = (*t1);
                s.erase(t1);
                if (nowfish > p1.second) {
                    nowres += p1.second * p1.first;
                    nowfish -= p1.second;
                }
                else {
                    nowres += p1.first * nowfish;
                    s.insert(make_pair(p1.first, p1.second - nowfish));
                    nowfish = 0;
                }
            }
            //cout << nowfish << " " << nowres << endl;
            res = max(res, nowres);
        }
        cout << res << endl;
        return 0;
    }
    //1234234752374578327589743285782370587327452374572397573204502374572304523757324095702347572345237570923945234524532423453245234523643353534534535345
    if (vn[vn.size() - 1].first < vm[0].first) {
        long long nowres = 0;
        for (long long i = 0; i < m; ++i) {
            //s.insert(make_pair(vm[i].second.second, vm[i].second.first));
            //cout << nowres << " " << allfish << " / ";
            if (i == 0) {
                nowres -= p * vm[0].first;
            }
            else {
                nowres -= p * (vm[i].first - vm[i - 1].first);
            }
            if (allfish > 0) {
                if (allfish > vm[i].second.first) {
                    allfish -= vm[i].second.first;
                    nowres += vm[i].second.first * vm[i].second.second;
                    s.insert(make_pair(vm[i].second.second, vm[i].second.first));
                }
                else {
                    nowres += allfish * vm[i].second.second;
                    vm[i].second.first -= allfish;
                    s.insert(make_pair(vm[i].second.second, allfish));
                    allfish = 0;
                }
            }
            if (allfish == 0) {
                    //cout << "!@#!@$!" << endl;
                long long can = vm[i].second.first, lli = vm[i].second.second;
                pair<long long, long long> p1 = make_pair(vm[i].second.second, 0);

                while (can > 0 && s.size() > 0) {
                    auto t1 = s.begin();
                    auto po = (*t1);
                    //cout << can << " " << lli << " " << p1.second << endl;
                    if (lli <= po.first) {
                        break;
                    }
                    s.erase(t1);
                    if (can >= po.second) {
                        can -= po.second;
                        p1.second += po.second;
                        nowres -= po.second * po.first;
                        nowres += po.second * lli;
                    }
                    else {
                        p1.second += can;
                        nowres -= can * po.first;
                        nowres += can * lli;
                        s.insert(make_pair(po.first, po.second - can));
                        can = 0;
                    }
                }
                if (p1.second > 0) {
                    s.insert(p1);
                }
            }
            res = max(res, nowres);
        }
        cout << res << endl;
        return 0;
    }

    long long oil = 0, lm = 0, ln = 0, nallf = 0, point = 0;
    while (lm < vm.size() || ln < vn.size()) {
            if (ln < vn.size() && (lm == vm.size() || vn[ln].first <= vm[lm].first)) {
                oil -= p * (vn[ln].first - point);
                nallf += vn[ln].second;
                point = vn[ln].first;
                ++ln;

            }
            else {
                oil -= p * (vm[lm].first - point);
                s.insert(make_pair(vm[lm].second.second, vm[lm].second.first));
                point = vm[lm].first;
                ++lm;

            }
            //cout << ln << " " << lm << " " << oil << endl;
            long long nowfish = nallf;
            auto t1 = s.end();
            long long nowres = oil;
            while (t1 != s.begin() && nowfish > 0) {
                --t1;
                auto p1 = (*t1);
                if (nowfish > p1.second) {
                    nowres += p1.second * p1.first;
                    nowfish -= p1.second;
                }
                else {
                    nowres += p1.first * nowfish;
                    //s.insert(make_pair(p1.first, p1.second - nowfish));
                    nowfish = 0;
                }
            }
            //cout << nowfish << " " << nowres << endl;
            res = max(res, nowres);
    }
    cout << res << endl;
    return 0;
}
