#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
long p, x[500001], y[500001], i, j, n, m, a[500001], b[500001], c[500001], sum[500001], ans=0, sum1;
pair <long, long> P[500001];
int main() {
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	cin >> n >> m >> p;
	for (i = 0; i < n; i++) {
		cin >> x[i] >> a[i];
		sum1 += a[i];
	}
	for (j = 0; j < m; j++) {
		cin >> y[j] >> P[j].second >> P[j].first;
	}
	if (p==0) {
		sort(P, P + m);
		for (i = m - 1; i >= 0; i--) {
			if (sum1>=P[i].second) {
				sum1 -= P[i].second;
				ans += P[i].second*P[i].first;
			}
			else {
				ans += sum1 * P[i].first;
				cout << ans;
				return 0;
			}
		}
	}
	cout << ans;
}