#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	int n, m, p;
	cin >> n >> m >> p;
	vector< pair<int, pair<int, int> > > arr(n + m);
	for (int i = 0; i < n; i++) {
		cin >> arr[i].first >> arr[i].second.first;
	}
	for (int i = n; i < n + m; i++) {
		cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second;
	}
	sort(arr.begin(), arr.end());
	long long k = 0;
	long long mx = 0;
	vector< pair<int, int> > nw;
	for (int i = 0; i < n + m; i++) {
		if (arr[i].second.second == 0) {
			k += arr[i].second.first;
		}
		else {
			nw.push_back({ arr[i].second.second, arr[i].second.first });
		}
		int j = nw.size() - 1;
		long long t = k;
		long long is = 0;
		sort(nw.begin(), nw.end());
		while (t > 0 && j >= 0) {
			if (t >= nw[j].second) { is += nw[j].first * nw[j].second; t -= nw[j].second; }
			else { is += t * nw[j].first; t = 0; }
			j--;
		}
		is -= arr[i].first * p;
		if (is > mx) { mx = is; }
	}
	cout << mx;
	return 0;
}