#include <bits/stdc++.h>
using namespace std;

struct cmp {
	bool operator ()(pair<int, int> a, pair<int, int> b) {
		return a > b;
	}
};

int main() {
	freopen("fisher.in", "r", stdin);
	#ifndef DEBUG
	freopen("fisher.out", "w", stdout);
	#endif
	
	int n, m, pp;
	scanf("%d%d%d", &n, &m, &pp);
	long long p = pp;
	vector<pair<int, int>> st(n + m);
	vector<int> a(n), b(m), c(m);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &st[i].first, &a[i]);
		st[i].second = i;
	}
	for (int j = 0; j < m; j++) {
		scanf("%d%d%d", &st[j + n].first, &b[j], &c[j]);
		st[j + n].second = j + n;
	}
	
	sort(st.begin(), st.end());
	
	multiset<pair<int, int>, cmp> ladder;
	long long best = 0;
	long long fish = 0;
	for (int i = 0; i < n + m; i++) {
		if (st[i].second < n) {
			int ind = st[i].second;
			fish += a[ind];
		} else {
			int ind = st[i].second - n;
			ladder.insert({c[ind], b[ind]});
		}
		
		long long area = 0;
		long long curwidth = 0;
		auto it = ladder.begin();
		while(it != ladder.end() && curwidth < fish) {
			if (curwidth + it->second <= fish) {
				area += ((long long) it->first) * it->second;
				curwidth += it->second;
			} else {
				area += (fish - curwidth) * it->first;
				curwidth = fish;
			}
			++it;
		}
		
		best = max(best, area - p * st[i].first);
	}
	cout << best << endl;
	
	return 0;
}
