#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <cassert>


using namespace std;

#define int long long int

struct event {
    int time, type, a, b;

    event() {}
    event(int _time, int _type, int _a, int _b) : time(_time), type(_type), a(_a), b(_b) {}

    bool operator<(const event &e) const {
        return time < e.time;
    }
};

struct sell {
    int b, c, cur, idx;

    sell() {}
    sell(int _b, int _c, int  _cur) : b(_b), c(_c), cur(_cur) {
        static int gidx = 0;
        idx = gidx++;
    }
    sell(int _b, int _c, int  _cur, int _idx) : b(_b), c(_c), cur(_cur), idx(_idx) {}

    bool operator<(const sell &s) const {
        if (c != s.c) {
            return c > s.c;
        }
        return idx < s.idx;
    }
};

int32_t main() {
#ifndef LOCAL
    assert(freopen("fisher.in", "r", stdin));
    assert(freopen("fisher.out", "w", stdout));
#endif // LOCAL
    int n, m, p;
    cin >> n >> m >> p;
    vector<event> evs;
    int x, a, b;
    int x1 = 0, xn = 0, y1 = 0, ym = 0;
    for (int i = 0; i < n; ++i) {
        cin >> x >> a;
        if (i == 0) {
            x1 = x;
        }
        if (i == n - 1) {
            xn = x;
        }
        evs.push_back(event(x, 0, a, -1));
    }
    for (int i = 0; i < m; ++i) {
        cin >> x >> a >> b;
        if (i == 0) {
            y1 = x;
        }
        if (i == m - 1) {
            ym = x;
        }
        evs.push_back(event(x, 1, a, b));
    }
    sort(evs.begin(), evs.end());
    if (p == 0) {
        vector<pair<int, int>> s;
        int fish = 0;
        int ans = 0;
        for (event e : evs) {
            if (e.type == 0) {
                fish += e.a;
            } else {
                s.push_back(make_pair(e.b, e.a));
            }
        }
        sort(s.begin(), s.end());
        int cfish = fish;
        for (int i = (int) s.size() - 1; cfish > 0 && i >= 0; --i) {
            int csell = min(cfish, s[i].second);
            ans += s[i].first * csell;
            cfish -= csell;
        }
        cout << ans << endl;
    } else if (ym < x1) {
        vector<pair<int, int>> s;
        int ans = 0;
        for (event e : evs) {
            if (e.type == 1) {
                s.push_back(make_pair(e.b, e.a));
            } else {
                break;
            }
        }
        sort(s.begin(), s.end());
        int sellp = s.size() - 1;
        int profit = 0;
        for (event e : evs) {
            if (e.type == 0) {
                int cfish = e.a;
                while (sellp >= 0 && cfish > 0) {
                    int csell = min(s[sellp].second, cfish);
                    profit += csell * s[sellp].first;
                    s[sellp].second -= csell;
                    if (s[sellp].second == 0) {
                        --sellp;
                    }
                    cfish -= csell;
                }
                ans = max(ans, profit - p * e.time);
            }
        }
        cout << ans << endl;
    } else if (xn < y1) {
        set<sell> s;
        int fish = 0;
        int ans = 0;
        for (event e : evs) {
            if (e.type == 0) {
                fish += e.a;
            } else {
                break;
            }
        }
        int profit = 0;
        for (event e : evs) {
            if (e.type == 1) {
                auto i = s.insert(sell(e.a, e.b, 0)).first;
                int icur = 0, iidx = i->idx, jb = 0, jc = 0, jcur = 0;
                icur = min(fish, i->b);
                fish -= icur;
                profit += icur * i->c;
                auto j = prev(s.end());
                for (; j != i; --j) {
                    int ct = min(i->b - icur, j->cur);
                    profit += (i->c - j->c) * ct;
                    jb = j->b;
                    jc = j->c;
                    jcur = j->cur - ct;
                    icur += ct;
                    if (icur == i->b) {
                        break;
                    }
                }
                s.erase(j, s.end());
                if (jcur > 0) {
                    s.insert(sell(jb, jc, jcur));
                }
                s.erase(sell(e.a, e.b, 0, iidx));
                s.insert(sell(e.a, e.b, icur, iidx));
                ans = max(ans, profit - p * e.time);
            }
        }
        cout << ans << endl;
    } else {
        vector<pair<int, int>> s;
        int fish = 0;
        int ans = 0;
        for (event e : evs) {
            if (e.type == 0) {
                fish += e.a;
            } else {
                s.push_back(make_pair(e.b, e.a));
                inplace_merge(s.begin(), prev(s.end()), s.end());
            }
            int profit = -e.time * p;
            int cfish = fish;
            for (int i = (int) s.size() - 1; cfish > 0 && i >= 0; --i) {
                int csell = min(cfish, s[i].second);
                profit += s[i].first * csell;
                cfish -= csell;
            }
            ans = max(ans, profit);
        }
        cout << ans << endl;
    }

    return 0;
}
