#pragma warning(disable:4996)
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<map>
#include<time.h>
#define ll long long int
using namespace std;

int n, m, p, x[500007], a[500007], y[500007], b[500007], c[500007];
map<int, ll>mp, fr, q;
ll s;

void upd() {
	ll t;
	while (fr.size() > 0 && mp.size() > 0) {
		if (fr.rbegin()->first > mp.begin()->first) {
			t = min(fr.rbegin()->second, mp.begin()->second);
			fr.rbegin()->second -= t;
			mp.begin()->second -= t;
			fr[mp.begin()->first] += t;
			mp[fr.rbegin()->first] += t;
			s -= (ll)t*(ll)mp.begin()->first;
			s += (ll)t*(ll)fr.rbegin()->first;
			while (mp.size()>0 && mp.begin()->second == 0)mp.erase(mp.begin()->first);
			while (fr.size()>0 && fr.rbegin()->second == 0)fr.erase(fr.rbegin()->first);
		}
		else {
			return;
		}
	}
}

void sol() {
	int i, j, ai = 0, bi = 0;
	s = 0;
	scanf("%d%d%d", &n, &m, &p);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &x[i], &a[i]);
		q[x[i]] = 1;
	}
	for (i = 0; i < m; i++) {
		scanf("%d%d%d", &y[i], &b[i], &c[i]);
		if (q[y[i]] == 1)q[y[i]] = 3;
		else q[y[i]] = 2;
	}
	ll ans = 0;
	int pr = 0;
	for (auto it = q.begin(); it != q.end(); it++) {
		s -= ((ll)it->first - (ll)pr)*(ll)p;
		if (it->second == 1) {
			mp[0] += a[ai];
			ai++;
		}
		else if (it->second == 2) {
			fr[c[bi]] += b[bi];
			bi++;
		}
		else {
			mp[0] += a[ai];
			ai++;
			fr[c[bi]] += b[bi];
			bi++;
		}
		//upd();
		ans = max(ans, s);
		pr = it->first;
		if ((double)clock() / CLOCKS_PER_SEC < 0.5) {
			upd();
			ans = max(ans, s);
		}
	}
	upd();
	ans = max(ans, s);
	printf("%I64d", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
#endif
	sol();
	return 0;
}