#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

struct fish
{
    long long x, a;
    fish(): x(0), a(0) {}
};

struct port
{
    long long y, b, c;
    port(): y(0), b(0), c(0) {}
};

bool cmps(port q, port w)
{
    return q.c > w.c;
}




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

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    long long n, m;
    long long p;
    cin >> n >> m >> p;
    vector <fish> t(n + 1);
    vector <port> s(m + 1);

    t[n].x = 2e9;
    s[m].y = 2e9;
    for (long long i = 0; i < n; ++i)
        cin >> t[i].x >> t[i].a;
    for (long long i = 0; i < m; ++i)
        cin >> s[i].y >> s[i].b >> s[i].c;
    if (p == 0)
    {
        t.pop_back(); s.pop_back();
        long long am = 0;
        for (int i = 0; i < n; ++i)
            am += t[i].a;
        sort(s.begin(), s.end(), cmps);
        long long ans = 0;
        int i = 0;
        while (i < m && am > 0)
        {
            int sold = min(1ll * s[i].b, am);
            ans += 1ll * s[i].c * sold;
            am -= sold;
            i++;
        }
        cout << ans << endl;
        return 0;
    }
    else if (s[m - 1].y < t[0].x)
    {

        t.pop_back(); s.pop_back();
        long long am = 0;
        sort(s.begin(), s.end(), cmps);
        long long ans = 0, mans = 0;
        int i = 0, j = 0;
        for (int j = 0; j < n; ++j)
        {
            am += t[j].a;
            while (i < m && am > 0)
            {
                int sold = min(1ll * s[i].b, am);
                ans += 1ll * s[i].c * sold;
                am -= sold;
                s[i].b -= sold;
                if (s[i].b == 0)
                    i++;
            }
            mans = max(mans, ans - 1ll * p * t[j].x);
        }
        cout << mans << endl;
        return 0;
    }
    multiset <pair <long long, long long> > used, left;
    long long flft = 0, ans = 0, mans = 0;
    long long i = 0, j = 0;
    while (i != n || j != m)
    {
        if (t[i].x < s[j].y)
        {
            flft += t[i].a;
            while (flft > 0 && left.size() > 0)
            {
                long long c = -left.begin()->first, b = left.begin()->second;
                left.erase(left.begin());
                if (b > flft)
                {
                    ans += flft * c;
                    b -= flft;
                    left.insert(make_pair(-c, b));
                    used.insert(make_pair(c, flft));
                    flft = 0;
                }
                else
                {
                    ans += c * b;
                    flft -= b;
                    used.insert(make_pair(c, b));
                }
            }
            mans = max(mans, ans - p * t[i].x);
            ++i;
        }
        else
        {
            long long leftb = s[j].b, leftc = s[j].c;
            if (flft > 0)
            {
                long long sold = min(leftb, flft);
                ans += sold * leftc;
                flft -= sold;
                leftb -= sold;
            }
            while (leftb > 0 && used.size() > 0 && used.begin()->first < s[j].c)
            {
                long long c = used.begin()->first, b = used.begin()->second;
                used.erase(used.begin());
                long long sold = min(leftb, b);
                b -= sold;
                leftb -= sold;
                ans += sold * (s[j].c - c);
                left.insert(make_pair(-c, sold));
                if (b > 0)
                    used.insert(make_pair(c, b));
            }
            if (leftb > 0)
                left.insert(make_pair(-s[j].c, leftb));
            if (s[j].b != leftb)
                used.insert(make_pair(s[j].c, s[j].b - leftb));


            mans = max(mans, ans - p * s[j].y);
            j++;
        }
    }
    cout << mans << endl;
}
