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

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());
	
	long long best = 0;
	long long av_fish = 0;
	long long profit = 0;
	set<pair<int, int>> av_opts, used_opts;
	for (int i = 0; i < n + m; i++) {
		if (st[i].second < n) {
			int ind = st[i].second;
			av_fish += a[ind];
			while (av_fish > 0 && !av_opts.empty()) {
				auto it = av_opts.end();
				--it;
				
				if (av_fish >= it->second) {
					profit += ((long long) it->first) * it->second;
					av_fish -= it->second;
					av_opts.erase(it);
				} else {
					profit += av_fish * it->first;
					int price = it->first;
					int amount = it->second - av_fish;
					av_opts.erase(it);
					av_opts.insert({price, amount});
					used_opts.insert({price, (int) av_fish});
					av_fish = 0;
				}
			}
		} else {
			int ind = st[i].second - n;
			// c[ind], b[ind]
			long long left = b[ind];
			int add = min(av_fish, left);
			left -= add;
			av_fish -= add;
			while (!used_opts.empty() && left > 0) {
				auto it = used_opts.begin();
				if (c[ind] <= it->first) {
					break;
				}
				if (left >= it->second) {
					left -= it->second;
					profit -= ((long long) it->first) * it->second;
					av_opts.insert({it->first, it->second});
					used_opts.erase(it);
				} else {
					int price = it->first;
					int amount = it->second - left;
					profit -= left * it->first;
					av_opts.insert({it->first, left});
					used_opts.erase(it);
					used_opts.insert({price, amount});
					left = 0;
				}
			}
			
			if (b[ind] - left > 0) {
				used_opts.insert({c[ind], b[ind] - left});
				profit += ((long long) c[ind]) * (b[ind] - left);
			}
			
			if (left > 0) {
				av_opts.insert({c[ind], left});
			}
		}
		best = max(best, profit - p * st[i].first);
	}
	cout << best << endl;
	
	return 0;
}
