#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

struct Fish {
    int x;
    ll a;
};

struct Sell {
    int x;
    ll b, c;
};

int n, m;
ll p;

vector<Fish> fish;
vector<Sell> sell;

void solve() {
    vector<int> all;

    fish.resize(n);
    for (int i = 0; i < n; i++) {
        scanf("%d%lld", &fish[i].x, &fish[i].a);
        all.push_back(fish[i].x);
    }

    sell.resize(m);
    for (int i = 0; i < m; i++) {
        scanf("%d%lld%lld", &sell[i].x, &sell[i].b, &sell[i].c);
        all.push_back(sell[i].x);
    }

    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());

    ll ans = 0;
    for (int x : all) {
        ll cur = -p * x;
        ll cntfish = 0;
        for (int i = 0; i < n; i++) {
            if (fish[i].x <= x) {
                cntfish += fish[i].a;
            } else break;
        }
        set< pair<ll, ll> > q;
        for (int i = 0; i < m; i++) {
            if (sell[i].x <= x) {
                q.insert({-sell[i].c, i});
            } else break;
        }
        while (cntfish > 0 && !q.empty()) {
            int i = q.begin()->se;
            q.erase(q.begin());
            cur += min(sell[i].b, cntfish) * sell[i].c;
            cntfish -= min(sell[i].b, cntfish);
        }
        ans = max(ans, cur);
    }

    printf("%lld\n", ans);
}

void solvep() {
    fish.resize(n);
    for (int i = 0; i < n; i++) {
        scanf("%d%lld", &fish[i].x, &fish[i].a);
    }

    sell.resize(m);
    for (int i = 0; i < m; i++) {
        scanf("%d%lld%lld", &sell[i].x, &sell[i].b, &sell[i].c);
    }

    ll cntfish = 0;
    for (int i = 0; i < n; i++) {
        cntfish += fish[i].a;
    }

    sort(sell.begin(), sell.end(), [](Sell s1, Sell s2) { return s1.c > s2.c; });

    ll ans = 0;
    for (int i = 0; i < m; i++) {
        ans += min(cntfish, sell[i].b) * sell[i].c;
        cntfish -= min(cntfish, sell[i].b);
    }

    printf("%lld\n", ans);
}

void solve23() {
    fish.resize(n);
    for (int i = 0; i < n; i++) {
        scanf("%d%lld", &fish[i].x, &fish[i].a);
    }

    sell.resize(m);
    for (int i = 0; i < m; i++) {
        scanf("%d%lld%lld", &sell[i].x, &sell[i].b, &sell[i].c);
    }

    if (sell.back().x < fish[0].x) {
        sort(sell.begin(), sell.end(), [](Sell s1, Sell s2) { return s1.c > s2.c; });
        ll ans = 0;
        int j = 0;
        ll cur = 0;
        for (int i = 0; i < n; i++) {
            if (i == 0) cur = -p * fish[i].x;
            else cur -= p * (fish[i].x - fish[i - 1].x);
            while (fish[i].a > 0 && j < m) {
                ll sold = min(sell[j].b, fish[i].a);
                sell[j].b -= sold;
                fish[i].a -= sold;
                cur += sold * sell[j].c;
                if (sell[j].b == 0) j++;
                if (fish[i].a == 0) break;
            }
            ans = max(ans, cur);
        }

        printf("%lld\n", ans);
    } else {
        ll ans = 0;
        ll cntfish = 0;
        for (int i = 0; i < n; i++) {
            cntfish += fish[i].a;
        }
        set< pair<ll, int> > q;
        for (int i = 0; i < m; i++) {
            q.insert({-sell[i].c, i});
        }
        vector<ll> to(m);
        ll cur = 0;
        while (cntfish > 0 && !q.empty()) {
            int i = q.begin()->se;
            q.erase(q.begin());

            ll del = min(sell[i].b, cntfish);
            cur += del * sell[i].c;
            cntfish -= del;
            sell[i].b -= del;
            to[i] += del;
            if (sell[i].b > 0) {
                q.insert({-sell[i].c, i});
            }
        }
        cur -= p * sell.back().x;
        ans = max(ans, cur);
        for (int i = m - 1; i >= 0; i--) {
            if (i == 0) cur += p * sell[i].x;
            else cur += p * (sell[i + 1].x - sell[i].x);
            cntfish += to[i];
            cur -= to[i] * sell[i].c;

            while (cntfish > 0 && !q.empty()) {
                int i = q.begin()->se;
                q.erase(q.begin());

                if (sell[i].x >= sell[i].x) continue;

                ll del = min(sell[i].b, cntfish);
                cur += del * sell[i].c;
                cntfish -= del;
                sell[i].b -= del;
                to[i] += del;
                if (sell[i].b > 0) {
                    q.insert({-sell[i].c, i});
                }
            }

            ans = max(ans, cur);
        }
        printf("%lld\n", ans);
    }
}

int main() {
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);

    while (scanf("%d%d%lld", &n, &m, &p) == 3) {
        if (n <= 1000 && m <= 1000 && p != 0) {
            solve();
        } else if (p == 0) {
            solvep();
        } else {
            solve23();
        }
    }
}
