#include <bits/stdc++.h>
#define point pair <int, int>
#define x first
#define y second
#define pb push_back
#define For(i, a, b) for(int i = a; i < b; ++i)
#define Out(i, a, b) for(int i = a - 1; i >= b; --i)
#define files(FileName) write(FileName); read(FileName)
#define read(FileName) freopen((FileName + ".in").c_str(), "r", stdin)
#define write(FileName) freopen((FileName + ".out").c_str(), "w", stdout)

using namespace std;

string FileName = "fisher";

typedef long long base;

int n, m, p;
int Fish[10002];
int Cost[10002];
int Size[10002];
base SumFish = 0;
base ans = 0, MyAns;
base SumSize = 0;

vector <pair <int, int>> need;
priority_queue <pair <int, int>> now;
priority_queue <pair <int, int>> tresh;

int main() {
    ios::sync_with_stdio(false);
    files(FileName);
    scanf("%d%d%d", &n, &m, &p);
    For(i, 1, n + 1) {
        int A; scanf("%d%d", &A, &Fish[i]);
        need.pb({A, -i});
    }
    For(i, 1, m + 1) {
        int A;  scanf("%d%d%d", &A, &Size[i], &Cost[i]);
        need.pb({A, i});
    }
    sort(need.begin(), need.end());
    For(i, 0, need.size()) {
        if (need[i].y < 0) {
            SumFish += Fish[-need[i].y];
        } else {
            tresh.push({Cost[need[i].y], need[i].y});
        }
        if (tresh.size() && now.size()) {
            auto A = tresh.top();
            auto B = now.top();
            if (tresh.top().x > -now.top().x) {
                tresh.pop();
                now.pop();
                MyAns += (base)Cost[A.y] * Size[A.y];
                MyAns -= (base)Cost[B.y] * Size[B.y];
                SumSize += Size[A.y];
                SumSize -= Size[B.y];
                tresh.push({Cost[B.y], B.y});
                now.push({-Cost[A.y], A.y});
            }
        }
        while (tresh.size() && SumSize < SumFish) {
            auto U = tresh.top(); tresh.pop();
            now.push({-Cost[U.y], U.y});
            MyAns += (base)Cost[U.y] * Size[U.y];
            SumSize += Size[U.y];
        }
        while (now.size()) {
            auto U = now.top();
            if (SumSize - Size[U.y] < SumFish) break;
            now.pop();
            tresh.push({Cost[U.y], U.y});
            MyAns -= (base)Cost[U.y] * Size[U.y];
            SumSize -= Size[U.y];
        }
        base NowAns = 0;
        if (SumSize < SumFish) {
            NowAns = MyAns;
        } else {
            if (now.size()) {
                NowAns = MyAns + (SumSize - SumFish) * now.top().x;
            }
        }
        ans = max(ans, NowAns - (base)need[i].x * p);
    }
    printf("%lld", ans);
}
