#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
#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;
    }
};

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;
    for (int i = 0; i < n; ++i) {
        cin >> x >> a;
        evs.push_back(event(x, 0, a, -1));
    }
    for (int i = 0; i < m; ++i) {
        cin >> x >> a >> b;
        evs.push_back(event(x, 1, a, b));
    }
    sort(evs.begin(), evs.end());
    vector<pair<int, int>> s;
    int fish = 0;
    int ans = 0;
    if (p == 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 {
        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;
}
