#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <list>
#include <ctime>
using namespace std;

int main() {
    srand(time(NULL));
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    long long n, m, p, money = 0, cnt = 0;
    cin >> n >> m >> p;
    vector <pair <long long, pair <long long, long long> > > data1, data2;
    for (long long i = 0; i < n; i++) {
        long long x, y;
        cin >> x >> y;
        data1.push_back({x, {y, -1}});
        cnt += y;
    }
    multiset <pair <long long, long long> > nums;
    for (long long j = 0; j < m; j++) {
        long long x, y, z;
        cin >> x >> y >> z;
        data2.push_back({x, {y, z}});
        nums.insert({z, y});
    }
   // sort(data.begin(), data.end());
    if (p == 0) {
        while (cnt != 0 && nums.size() != 0) {
            auto v = *(--nums.end());
            if (cnt < v.second) {
                money += cnt * v.first;
                cnt = 0;
            } else {
                cnt -= v.second;
                money += v.first * v.second;
            }
            nums.erase(nums.find(v));
        }
        cout << money;
        return 0;
    }
    long long maxm = 0;
    if (data2[m - 1].first < data1[0].first) {
        cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt = data1[i].second.first;
            long long cnt1 = cnt;
            while (cnt1 != 0 && nums.size() != 0) {
                auto v = *(--nums.end());
                if (cnt1 < v.second) {
                    money += cnt1 * v.first;
                    nums.erase(nums.find(v));
                    nums.insert({v.first, v.second - cnt1});
                    cnt1 = 0;
                } else {
                    cnt1 -= v.second;
                    money += v.first * v.second;
                    nums.erase(nums.find(v));
                }
            }
            maxm = max(maxm, money - data1[i].first * p);
        }
        cout << maxm << endl;
        return 0;
    }
    vector <int> used(1000001, 0);
    pair <int, int> nfu;
    if (data2[0].first > data1[n - 1].first) {
        long long cnt1 = cnt;
        money = 0;
        while (cnt1 != 0 && nums.size() != 0) {
            auto v = *(--nums.end());
            if (cnt1 < v.second) {
                money += cnt1 * v.first;
                nums.erase(nums.find(v));
                nums.insert({v.first, v.second - cnt1});
                used[v.first] += cnt;
                cnt1 = 0;
            } else {
                used[v.first] += v.second;
                cnt1 -= v.second;
                money += v.first * v.second;
                nums.erase(nums.find(v));
            }
        }
        maxm = max(maxm, money - data2[m - 1].first * p);
        for (int i = m - 1; i >= 1; i--) {
            long long x = data2[i].second.first, y = data2[i].second.second;
            long long d;
            if (used[x] >= y) {
                used[x] -= y;
                money -= x * y;
                d = y;
            } else {
                money -= x * used[x];
                used[x] = 0;
                d = used[x];
            }
            cnt1 = d;
            while (cnt1 != 0 && nums.size() != 0) {
                auto v = *(--nums.end());
                if (cnt1 < v.second) {
                    money += cnt1 * v.first;
                    nums.erase(nums.find(v));
                    nums.insert({v.first, v.second - cnt1});
                    used[v.first] += cnt;
                    cnt1 = 0;
                } else {
                    used[v.first] += v.second;
                    cnt1 -= v.second;
                    money += v.first * v.second;
                    nums.erase(nums.find(v));
                }
            }
            maxm = max(maxm, money - data2[i - 1].first * p);
        }
        cout << maxm;
    }
}
