#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)

const int LEN = 500500;

struct fish
{
    ll x, cnt;
};

struct mag
{
    ll x, c, cnt;
};

bool comp(const mag &a, const mag &b)
{
    return (a.c > b.c);
}

ll n, m, p, res, kol;
fish ar[LEN];
mag ar1[LEN];


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

    cin >> n >> m >> p;
    for (int i = 0; i < n; i++)
    {
        cin >> ar[i].x >> ar[i].cnt;
        kol += ar[i].cnt;
    }

    for (int i = 0; i < m; i++)
        cin >> ar1[i].x >> ar1[i].cnt >> ar1[i].c;

    if (p == 0)
    {
        sort(ar1, ar1 + m, comp);
        for (int i = 0; i < m; i++)
        {
            res += min(kol, ar1[i].cnt) * ar1[i].c;
            kol -= min(kol, ar1[i].cnt);
        }

        cout << res;
        return 0;
    }

    return 0;
}

/*
3 4 0
SSSS
EESW
ENWW
*/
