#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <fstream>

using namespace std;

long long check(multiset<pair<int, int>> const& buy, long long fish)
{
    long long ans = 0;
    for (auto i : buy)
    {
        ans += -i.first * min((long long) i.second, fish);
        fish -= i.second;
        if (fish <= 0) {break;};
    }
    return ans;
}


bool cmp(vector<int> const& a, vector<int> const& b)
{
    return a[2] > b[2];
}

int main()
{
    ifstream cin("fisher.in");
    ofstream out("fisher.out");

    long long n, m, p;
    cin >> n >> m >> p;

    if (p == 0)
    {
        long long fish = 0;
        multiset<pair<int, int>> ys;
        for(int i = 0; i < n; i++)
        {
            int x, a;
            cin >> x >> a;
            fish += a;
        }
        for (int j = 0; j < m; j++)
        {
            int y, b, c;
            cin >> y >> b >> c;
            ys.insert({-c, b});
        }
        long long ans = 0;
        cout << check(ys, fish);
        out << check(ys, fish);
        return 0;
    }
    else if (m > 8500 || n > 8500)
    {
        vector<vector<int>> ys;
        vector<vector<int>> xs;
        for (int i = 0; i < n; i++)
        {
            int x, a;
            cin >> x >> a;
            xs.push_back({x, a});
        }
        for (int j = 0; j < m; j++)
        {
            int y, b, c;
            cin >> y >> b >> c;
            ys.push_back({y, b, c});
        }
        if (ys.back() < xs.front())
        {
            sort(ys.begin(), ys.end(), cmp);
            long long ans = 0;
            long long curans = 0;
            long long fish = 0;
            int curit = 0;
            for (auto i : xs)
            {
                fish = i[1];
                while (fish)
                {
                    int d = min(fish, (long long) ys[curit][1]);
                    fish -= d;
                    curans += ys[curit][2] * d;
                    ys[curit][1] -= d;
                }
                ans = max(ans, curans - p * i[0]);
            }
            cout << ans;
            out << ans;
            return 0;
        }




        if (xs.back() < ys.front())
        {
            long long fish = 0;
            for (auto i : xs)
            {
                fish += i[1];
            }
            return 0;
        }
    }
    else
    {
        vector<vector<int>> k;
        for(int i = 0; i < n; i++)
        {
            int x, a;
            cin >> x >> a;
            k.push_back({x, a});
        }
        for (int j = 0; j < m; j++)
        {
            int y, b, c;
            cin >> y >> b >> c;
            k.push_back({y, b, c});
        }
        sort(k.begin(), k.end());
        long long best = 0;
        long long fish = 0;
        multiset<pair<int, int>> buy;
        for (auto i : k)
        {
            if (i.size() == 2)
            {
                fish += i[1];
            }
            else
            {
                buy.insert({-i[2], i[1]});
            }
            best = max((check(buy, fish) - p * i[0]), best);
            //cout << best << ' ' << check(buy, fish) << ' ' << fish << endl;
        }
        //cout << best;
        out << best;
        return 0;
    }
}

