#include <bits/stdc++.h>
using namespace std;
#define ll long long

struct point{
    ll x, val;
    point() {}
    point(ll x, ll val): x(x), val(val) {}
    void read() {cin >> x >> val;}
};

struct shop {
    ll x, val, a;
    shop() {}
    shop(ll x, ll val, ll a): x(x), val(val), a(a) {}
    void read() {cin >> x >> val >> a;}
};

bool cmp(shop a, shop b) {
    return a.a > b.a;
}

ll n, m, p;
point po[50001];
shop s[50001];
ll sum[50001];

struct point3{
    bool type; ///0 - Ловля. 1 - Продажа
    ll x, val, a;
    point3() {}
    point3(point q): type(0), x(q.x), val(q.val), a(0) {}
    point3(shop q): type(1), x(q.x), val(q.val), a(q.a) {}
};
point3 pts[5000];

bool cmp3(point3 a, point3 b) {
    return a.x < b.x;
}

ll countsum(int finish) {
    int ptr1 = 0; point ps[1001];
    int ptr2 = 0; shop ss[1001];
    for (int i = 0; i <= finish; i++) {
        if (pts[i].type == 0) {ps[ptr1] = point(pts[i].x, pts[i].val); ptr1++;}
        if (pts[i].type == 1) {ss[ptr2] = shop(pts[i].x, pts[i].val, pts[i].a); ptr2++;}
    }

    ll sum = 0;
    sum -= pts[finish].x * p;

    sort(&ss[0], &ss[ptr2], cmp);
    ll ulov = 0;
    for (int i = 0; i < ptr1; i++) ulov += ps[i].val;

    int pptr2 = 0;
    while (pptr2 < ptr2 && ulov > 0) {
        ll kol = min(ss[pptr2].val, ulov);
        ulov -= kol;
        ss[pptr2].val -= kol;
        sum += kol * ss[pptr2].a;
        if (ss[pptr2].val == 0) pptr2++;
    }
    return sum;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    cin >> n >> m >> p;


    for (int i = 0; i < n; i++) po[i].read();
    for (int i = 0; i < m; i++) s[i].read();

    if (p == 0) {
        ll ulov = 0;
        for (int i = 0; i < n; i++) ulov += po[i].val;
        sort(&s[0], &s[m], cmp);
        ll sum = 0;
        for (int i = 0; i < m; i++) {
            if (ulov <= 0) break;
            sum += min(ulov, s[i].val) * s[i].a;
            ulov -= min(ulov, s[i].val);
        }
        cout << sum;
        return 0;
    }

    if (s[m - 1].x < po[0].x) {
        sort(&s[0], &s[m], cmp);
        int pointer = 0;

        sum[0] -= po[0].x * p;
        ll ulov = po[0].val;
        while (pointer < m && ulov > 0) {
            if (s[pointer].val == 0) pointer++;
            ll kol = min(s[pointer].val, ulov);
            ulov -= kol;
            s[pointer].val -= kol;
            sum[0] += kol * s[pointer].a;
        }

        for (int i = 1; i < n; i++) {
            sum[i] = sum[i - 1] - (po[i].x - po[i - 1].x) * p;
            ll ulov = po[i].val;
            while (pointer < m && ulov > 0) {
                if (s[pointer].val == 0) {pointer++;}
                ll kol = min(s[pointer].val, ulov);
                ulov -= kol;
                s[pointer].val -= kol;
                sum[i] += kol * s[pointer].a;
            }
            if (pointer < 0) break;
        }

        ll maxsum = 0;
        for (int i = 0; i < n; i++) {maxsum = max(maxsum, sum[i]);}
        cout << maxsum;
        return 0;
    }

    if (n <= 1000 && m <= 1000) {
        int ptr = 0;
        for (int i = 0; i < n; i++) {pts[ptr] = point3(po[i]); ptr++;}
        for (int i = 0; i < m; i++) {pts[ptr] = point3(s[i]); ptr++;}
        sort(&pts[0], &pts[ptr], cmp3);

        ll sum = 0;
        for (int i = 0; i < ptr; i++) {
            sum = max(sum, countsum(i));
        }
        cout << sum;
        return 0;
    }
    return 0;
}
