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

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;
}

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;
	}
	return 0;
}