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

struct segtree{
    segtree *l = NULL, *r = NULL;
    long long sum = 0, cost = 0, lb, rb;
};

void add(segtree *p, long long pos, long long val){
    p->sum += val;
    p->cost += pos*val;
    //cerr << "add " << p->lb << " " << p->rb << " " << p->sum << " " << p->cost << endl;
    if(p->lb == p->rb)
        return;
    long long m = (p->lb+p->rb)/2;
    if(pos <= m){
        if(p->l == NULL){
            p->l = new segtree;
            p->l->lb = p->lb;
            p->l->rb = m;
        }
        add(p->l, pos, val);
    }
    else{
        if(p->r == NULL){
            p->r = new segtree;
            p->r->lb = m+1;
            p->r->rb = p->rb;
        }
        add(p->r, pos, val);
    }
}

pair<long long, long long> query(segtree *p, long long l){
    if(p == NULL || p->rb < l)
        return {0, 0};
    if(p->lb >= l)
        return {p->sum, p->cost};
    pair<long long, long long> q1 = query(p->l, l), q2 = query(p->r, l);
    return {q1.first + q2.first, q1.second + q2.second};
}

int main(){

    ios::sync_with_stdio(false);
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);

    segtree *p = new segtree;
    p->lb = 1;
    p->rb = 1e6+1;

    long long n, m;
    long long k;
    cin >> n >> m >> k;

    vector< pair<long long, pair<long long, long long> > > a(n+m);

    for(int i = 0; i < n; i++){
        long long x;
        long long f;
        cin >> x >> f;
        a[i] = {x, {f, -1}};
    }

    for(int i = 0; i < m; i++){
        long long x;
        long long b, c;
        cin >> x >> b >> c;
        a[n+i] = {x, {b, c}};
    }

    sort(a.begin(), a.end());

    clock_t start = clock();;

    long long ans = 0, fish = 0;
    for(int i = 0; i < n+m; i++){
        if(start-clock() > 0.95*CLOCKS_PER_SEC)
            break;
        long long x = a[i].first;
        if(a[i].second.second == -1){
            fish += a[i].second.first;
            //cerr << "fish = " << fish << endl;
        }
        else{
            add(p, a[i].second.second, a[i].second.first);
            //cerr << "rate " << a[i].second.second << " " << a[i].second.first << endl;
        }
        if(p->sum <= fish)
            ans = max(ans, p->cost - k*x);
        else{
            if(false && n > 1e5 && rand()%100 > 95)
                continue;
            long long l = 1, r = 1e6+1;
            while(l != r){
                long long t = (l+r)/2;
                long long sum = query(p, t).first;
                if(sum >= fish)
                    l = t+1;
                else
                    r = t;
            }
            pair<long long, long long> q = query(p, l);
            //cerr << l << " profit = " << query(p, l).second  << " + "  << (l-1)*(fish-sum) << " + " << - k*x << endl;
            ans = max(ans, q.second + (l-1)*(fish-q.first) - k*x);
        }
    }

    cout << ans << endl;

    return 0;
}
