#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <ctime>
#include <climits>

using namespace std;

int main() {
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);

	long long n, m, p;
	cin >> n >> m >> p;

	long long x, a;
	vector<pair<pair<long long, long long>, pair<long long, long long> > > v;
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &x, &a);
		v.push_back(make_pair(make_pair(x, 0), make_pair(a, 0)));
	}
	long long y, b, c;
	for (long long i = 0; i < m; i++) {
		scanf("%lld%lld%lld", &y, &b, &c);
		v.push_back(make_pair(make_pair(y, 1), make_pair(c, b)));
	}
	sort(v.begin(), v.end());
	long long neg = 0, mx = 0;
	long long fish = 0;
	priority_queue<pair<long long, long long> > h;
	for (auto el : v) {
		auto f = el.first;
		auto s = el.second;
		neg = f.first;
		if (f.second == 0) {
			fish += s.first;
		}
		else {
			h.push(s);
		}

		priority_queue<pair<long long, long long> > hah = h;

		long long sum = 0, tempfish = fish;
		for (int j = 0; j < h.size(); j++) {
			if (tempfish == 0) break;

			auto kek = hah.top();
			hah.pop();

			long long wtf = min(tempfish, kek.second);
			tempfish -= wtf;
			sum += wtf * kek.first;
		}
		mx = max(mx, sum - neg * p);
	}
	cout << mx;

	return 0;
}
