#include <bits/stdc++.h>

using namespace std;

const int MX_SZ = 5e+5 + 42;

struct shop
{
    long long y, b, c;
    shop() {}
    shop(long long y0, long long b0, long long c0) : y(y0), b(b0), c(c0) {}
};

inline bool by_cost(const shop &s1, const shop &s2)
{
    return s1.c > s2.c;
}

pair<long long, long long> a[MX_SZ];
shop b[MX_SZ];

void solve2(long long n, long long m, long long p)
{
    long long ans = 0;
    long long gain = 0;
    sort(b, b + m, by_cost);
    int p1 = 0;
    for (int i = 0; i < n; i++)
    {
        while (p1 != m and a[i].first != 0)
        {
            long long to_sell = min(b[p1].b, a[i].first);
            a[i].first -= to_sell;
            b[p1].b -= to_sell;
            gain += to_sell * b[p1].c;
            ans = max(ans, gain - 2 * p * a[i].first);
            if (b[p1].b == 0)
            {
                p1++;
            }
        }
    }
    cout << ans;
}

int main()
{
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    int n, m, p;
    cin >> n >> m >> p;
    long long sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].first >> a[i].second;
        sum += a[i].second;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> b[i].y >> b[i].b >> b[i].c;
    }
    if (b[m - 1].y < a[0].first)
    {
        solve2(n, m, p);
    }
    else
    {
        sort(b, b + m, by_cost);
        long long ans = 0;
        for (int i = 0; i < m; i++)
        {
            long long cr = min(sum, b[i].b) * b[i].c;
            sum -= min(sum, b[i].b);
            ans += cr;
        }
        cout << ans;
    }
}
