#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#pragma comment(linker, "/stack:268435456")
#define cs(x) (int)x.size()
#define ll long long
#define ld long double
#define mp make_pair

using namespace std;


int main() {
	iostream::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	ll p;
	cin >> p;
	vector<pair<ll , ll> > arr;
	arr.reserve(n + m);
	vector<ll> fish(n);
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		arr.push_back(mp(a, i));
		fish[i] = b;
	}
	vector<pair<ll, ll> > trade(m);
	vector<ll> use(m);
	for (int i = 0; i < m; i++) {
		int x, a, b;
		cin >> x >> a >> b;
		arr.push_back(mp(x, n + i));
		trade[i] = mp(a, b);
	}
	ll curans = 0;
	ll curmoney = 0;
	ll extrafish = 0;
	ll cost = 0;
	ll lastdist = 0;
	sort(arr.begin(), arr.end());
	set<pair<ll, ll> > usedtrade;
	set<pair<ll, ll> > notfulltrade;
	for (auto ev : arr) {
		cost -= (ev.first - lastdist)*p;
		lastdist = ev.first;
		if (ev.second >= n) {
			auto base = trade[ev.second - n];
			ll canuse = base.first;
			if (extrafish >= canuse) {
				use[ev.second - n] = canuse;
				cost += base.second * canuse;
				extrafish -= canuse;
			}
			else {
				use[ev.second - n] = extrafish;
				cost += base.second * extrafish;
				canuse -= extrafish;
				extrafish = 0;
				while (canuse && cs(usedtrade)) {
					auto cur = *usedtrade.begin();
					if (cur.first >= base.second)
						break;
					ll cangive = use[cur.second];
					if (cangive <= canuse) {
						cost -= cangive * cur.first;
						use[cur.second] = 0;
						notfulltrade.insert(cur);
						use[ev.second - n] += cangive;
						cost += cangive * base.second;
						canuse -= cangive;
						usedtrade.erase(cur);
					}
					else {
						cost -= canuse * cur.first;
						use[cur.second] -= canuse;
						notfulltrade.insert(cur);
						use[ev.second - n] += canuse;
						cost += canuse * base.second;
						canuse = 0;
						break;
					}
				}
				if (canuse)
					notfulltrade.insert(mp(base.second, ev.second-n));
			}
		}
		else {
			auto f = fish[ev.second];
			while (f > 0 && cs(notfulltrade)) {
				auto cur = *notfulltrade.rbegin();
				ll canuse = trade[cur.second].first - use[cur.second];
				if (canuse <= f) {
					f -= canuse;
					cost += canuse * trade[cur.second].second;
					use[cur.second] += canuse;
					usedtrade.insert(cur);
					notfulltrade.erase(cur);
				}
				else {
					cost += f * cur.first;
					use[cur.second] += f;
					usedtrade.insert(cur);
					f = 0;
					break;
				}
			}
			extrafish += f;
		}
		curans = max(curans, cost);
	}
	cout << curans << endl;
	return 0;
}