#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>

using namespace std;

#define NAME "fisher"
#define _NO_WARNINGS
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define all(x) x.begin(), x.end()
#define forn(i, n) for(int i = 0; i < n; i++)
#define ll long long
#define pii pair<ll, ll>

bool comp(pii a, pii b) {
	if (a.first != b.first)
		return a.first > b.first;
	return a.second < b.second;
}

struct shop {
	int y, b, c;
	shop() {
		;
	}
	shop(int _y, int _b, int _c) : y(_y), b(_b), c(_c) {};
};

bool comp1(shop a, shop b) {
	if (a.c != b.c)
		return a.c > b.c;
	return a.b > b.b;
}

int main() {
	ios_base::sync_with_stdio(0);
	FREOPEN;
	ll n, m, p;
	cin >> n >> m >> p;
	if (p == 0) {
		ll sum = 0;
		forn(i, n) {
			ll a;
			ll x;
			cin >> x >> a;
			sum += a;
		}
		vector<pii> mas(m);
		forn(i, m) 
			cin >> n >> mas[i].second >> mas[i].first;
		sort(all(mas), comp);
		int j = 0;
		ll ans = 0;
		while (j < m && sum > 0) {
			ans += mas[j].first * min(sum, mas[j].second);
			sum -= min(sum, mas[j].second);
			j++;
		}
		cout << ans;
		return 0;
	}
	else {
		vector<pii> mas(n);
		ll s = 0;
		forn(i, n) {
			cin >> mas[i].first >> mas[i].second;
			s += mas[i].second;
		}
		vector<shop> riv;
		forn(i, m) {
			ll y, b, c;
			cin >> y >> b >> c;
			riv.push_back(shop(y, b, c));
		}
		ll ans = 0;
		ll now = 0;
		if (riv[m - 1].y < mas[0].first) {
			sort(all(riv), comp1);
			ll s = 0;
			int r = riv[0].b;
			ll k = 0;
			forn(i, n) {
				s += mas[i].second;
				while (r < n) {
					if (mas[i].second > k) {
						mas[i].second -= k;
						now += (riv[r].c * k);
						r++;
						k = riv[r].b;
					}
					else {
						now += mas[i].second * k;
						k = riv[r].b - mas[i].second;
						break;
					}
				}
				ans = max(ans, now - mas[i].first);
			}
			cout << ans;
			return 0;
		}
		else {
			;
		}

	}
	return 0;
}