#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define FOR(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define MAXN 100000
#define S second
#define F first
using namespace std;

ll x[MAXN + 1];
ll a[MAXN + 1];
ll y[MAXN + 1];
#define FILENAME "fisher"
int main()
{
    freopen(FILENAME".in", "r", stdin);
    freopen(FILENAME".out", "w", stdout);
    ll n, m, p;
    cin >> n >> m >> p;
    vector<pair<ll,ll> > b(m);
    FOR(i, n)
        cin >> x[i] >> a[i];
    FOR(i, m)
        cin >> y[i] >> b[i].S >> b[i].F;
    if(p == 0){
        FOR(i, n)
            b[i].F *= -1;
        sort(b.begin(), b.end());
        ll s = 0;
        FOR(i, n)
            s += a[i];
        ll ans = 0, now = 0;
        while(s > 0 && now < m){
            if(s >= b[now].S){
                s -= b[now].S;
                ans += b[now].S * (-b[now].F);
                now++;
            }
            else{
                ans += s * (-b[now].F);
                s = 0;
            }
        }
        cout << ans;
        return 0;
    }
}

