#include <bits/stdc++.h>

using namespace std;


void print(vector<long long> s){
    for (long long i = 0; i < s.size(); i++)
        cout << s[i] << " ";
    cout << endl;
}



long long foo(vector<vector<long long> > lst, long long cnt, long long cur){
    vector<vector<long long> > s;
    for (long long i = 0; i < cur; i++){
        s.push_back(lst[i]);
        swap(s[i][0], s[i][3]);
        swap(s[i][1], s[i][2]);
    }
    sort(s.begin(), s.end());
    reverse(s.begin(), s.end());
    cur = 0;
    long long n = s.size();
    long long answer = 0;
    while (cnt > 0 && cur < n){
        answer += s[cur][0] * min(cnt, s[cur][1]);
        long long k = cnt;
        cur += 1;
    }
    return answer;
}


int main()
{
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    long long n, m, p;
    cin >> n >> m >> p;
    if (p == 0){
        vector<pair<int, int> > s(n);
        for (int i = 0; i < n; i++)
            cin >> s[i].first >> s[i].second;
        vector<vector<long long> > lst(m);
        for (int i = 0; i < m; i++){
            lst[i].resize(3);
            cin >> lst[i][1] >> lst[i][2] >> lst[i][0];
        }
        long long summa = 0;
        for (int i = 0; i < n; i++)
            summa += s[i].second;
        long long answer = 0;
        sort(lst.begin(), lst.end());
        reverse(lst.begin(), lst.end());
        for (int i = 0; i < m; i++){
            answer += lst[i][0] * min(lst[i][2], summa);
            summa -= min(lst[i][2], summa);
        }
        cout << answer;
        return 0;
    }
    if (lst[m - 1][1] <= s[0].first){
        vector<pair<int, int> > s(n);
        for (int i = 0; i < n; i++)
            cin >> s[i].first >> s[i].second;
        vector<vector<long long> > lst(m);
        for (int i = 0; i < m; i++){
            lst[i].resize(3);
            cin >> lst[i][1] >> lst[i][2] >> lst[i][0];
        }
        vector<vector<long long> > dp(n);
        for (int i = 0; i < n; i++)
            dp[i].resize(2);
        dp[0][0] = s[0].first;
        dp[0][1] = s[0].second;
        for (int i = 1; i < n; i++){
            dp[i] = dp[i - 1];
            dp[i][0] = s[i].first;
            dp[i][1] += s[i].second;
        }
        vector<long long> answer(n);
        for (int i = 0; i < n; i++)
            answer[i] = 0;
        int cur = 0;
        int now = 0;
        sort(lst.begin(), lst.end());
        reverse(lst.begin(), lst.end());
        long long pr = 0;
        while (cur < m && now < n){
            if (now > 0){
                answer[now] = answer[now - 1];
                dp[now][1] -= pr;
            }
            pr += dp[now][1];
            while (cur < m){
                answer[now] += lst[cur][0] * min(lst[cur][2], dp[now][1]);
                long long k = lst[cur][2];
                lst[cur][2] -= min(lst[cur][2], dp[now][1]);
                dp[now][1] -= min(k, dp[now][1]);
                if (dp[now][1] != 0)
                    cur += 1;
                else
                    break;
            }
            now += 1;
        }
        //print(answer);
        int x = 0;
        for (int i = 0; i < n; i++)
            if (answer[i] - p * dp[i][0] > answer[x] - p * dp[x][0])
                x = i;
        if (answer[x] - p * dp[x][0] > 0)
            cout << answer[x] - p * dp[x][0] << endl;
        else
            cout << 0;
    }
    vector<vector<long long> > s;
    for (long long i = 0; i < n; i++){
        vector<long long> x(3);
        cin >> x[0] >> x[2];
        x[1] = 0;
        s.push_back(x);
    }
    vector<vector<long long> > lst;
    for (long long i = 0; i < m; i++){
        vector<long long> x(4);
        x[1] = 1;
        cin >> x[0] >> x[2] >> x[3];
        s.push_back(x);
        lst.push_back(x);
    }
    sort(s.begin(), s.end());
    vector<long long> answer(n + m);
    vector<long long> cnt(n + m);
    long long cur = 0;
    long long pr = 0;
    for (long long i = 0 ; i < n + m; i++){
        vector<long long> x = s[i];
        if (i == 0 && x.size() == 3){
            cnt[i] = x[2];
            answer[i] = -p * x[0];
            pr = x[0];
            continue;
        }
        if (i == 0 && x.size() == 4){
            cnt[i] = 0;
            answer[i] = -p * x[0];
            pr = x[0];
            cur += 1;
            continue;
        }
        if (x.size() == 3){
            cnt[i] = cnt[i - 1] + x[2];
            answer[i] = answer[i - 1] - p * (x[0] - pr);
            pr = x[0];
            continue;
        }
        else{
            cur += 1;
            cnt[i] = cnt[i - 1];
            answer[i] = foo(lst, cnt[i], cur) - x[0] * p;
            pr = x[0];
        }
    }
    long long x = 0;
    for (long long i = 0; i < answer.size(); i++)
        if (answer[x] < answer[i])
            x = i;
    cout << max(answer[x], 0LL);
    return 0;
}
