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

#define NAME "fisher"

struct base {
	int y;
	int count;
	int price;

	base() {}
	base(int y, int count, int price) : y(y), count(count), price(price) {}
};

bool operator<(const base &u, const base &v) {
	if (u.price != v.price) return u.price < v.price;
	if (u.count != v.count) return u.count < v.count;
	return u.y < v.y;
}

bool operator==(const base &u, const base &v) {
	return u.y == v.y;
}

int main() {
#ifndef NO_FILES
	freopen(NAME".in", "r", stdin);
	freopen(NAME".out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m, p;
	cin >> n >> m >> p;
	vector<pair<int, int>> x(n);
	for (int i = 0; i < n; ++i)
		cin >> x[i].first >> x[i].second;

	vector<base> y(m);
	for (int i = 0; i < m; ++i)
		cin >> y[i].y >> y[i].count >> y[i].price;

	if (p == 0) {
		long long s = 0;
		for (auto p: x)
			s += p.second;
		sort(y.rbegin(), y.rend(), [](base u, base v) {
			return u.price < v.price;
		});
		long long ans = 0;
		for (auto cy: y) {
			long long x = min(s, (long long)cy.count);
			ans += 1ll * x * cy.price;
			s -= x;
		}

		cout << ans << endl;
	} else if (y[m - 1].y < x[0].first) {
		sort(y.rbegin(), y.rend(), [](base u, base v) {
			return u.price < v.price;
		});
		auto cy = y.begin();
		long long ans = 0;
		long long cinc = 0;
		for (int i = 0; i < n; ++i) {
			long long cp = 1ll * p * x[i].first;
			int s = x[i].second;
			while (cy != y.end() and s > 0) {
				int x = min(s, cy->count);
				cinc += 1ll * x * cy->price;
				s -= x;
				cy->count -= x;
				if (cy->count == 0)
					++cy;
			}
			ans = max(ans, cinc - cp);
		}
		cout << ans;
	} /*else if (x[n - 1].first < y[0].y) {
		long long s = 0;
		for (auto p: x)
			s += p.second;
		
		long long cinc = 0;
		long long ans = 0;
		for (int i = 0; i < m; ++i) {
			long long cp = 1ll * p * y[i].y;
			int x = min(s, (long long)y[i].count);
			cinc += 1ll * x * y[i].price;
			s -= x;

			ans = max(ans, cinc - cp);
		}
		cout << ans << endl;
	} */
	else {
		vector<int> events;
		for (int i = 0; i < n; ++i)
			events.push_back(i);
		for (int i = 0; i < m; ++i)
			events.push_back(-i - 1);
		sort(events.begin(), events.end(), [&](int i, int j) {
			int x1 = (i >= 0) ? x[i].first : y[-i - 1].y;
			int x2 = (j >= 0) ? x[j].first : y[-j - 1].y;
			if (x1 != x2) return x1 < x2;
			return i > j;
		});

		long long s = 0;
		long long ans = 0;
		long long cinc = 0;
		set<base> b;
		b.insert(base(1488228228, 0, 1488228228));
		auto pm = b.begin();
		int cc = 0;
		for (int re: events) {
			long long cp;
			if (re < 0) {
				int e = -re - 1;
				auto &q = y[e];
				b.insert(q);
				cp = 1ll * p * y[e].y;
				if (q < *pm) {
					if (s > 0) {
						int u = min(s, (long long)q.count);
						cc = u;
						s -= u;
						cinc += 1ll * u * q.price;
						--pm;
						assert(*pm == q);
					}
				} else {
					int qc = q.count;
					while (*pm < q and qc > 0) {
						int u = min(cc, qc);
						cinc -= 1ll * u * pm->price;
						cinc += 1ll * u * q.price;
					   	qc -= u;
						cc -= u;
						if (cc == 0) {
							++pm;
							cc = pm->count;
						}
					}
					while (s > 0 and (pm != b.begin() or cc < pm->count)) {
						int u = min(s, (long long)pm->count - cc);
						cinc += 1ll * u * pm->price;
						cc += u;
						s -= u;
						if (s > 0 and pm != b.begin()) {
							--pm;
							cc = 0;
						}
					}
				}
				ans = max(ans, cinc - cp);
			} else {
				int e = re;
				cp = 1ll * p * x[e].first;
				s += x[e].second;
				while (s > 0 and (pm != b.begin() or cc < pm->count)) {
					int u = min(s, (long long)pm->count - cc);
					cinc += 1ll * u * pm->price;
					cc += u;
					s -= u;
					if (s > 0 and pm != b.begin()) {
						--pm;
						cc = 0;
					}
				}
			}
			ans = max(ans, cinc - cp);
		}
		cout << ans << endl;
	}
}

