#define _ijps 0
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define name "fisher"
typedef long long ll;
#define forn(i, n) for(int i = 0; i < n; i++)
#define fornn(i, a, n) for(int i = a; i < n; i++)
#define mk make_pair

const int dd = 1e6 + 7;
const int infi = 1e9 + 7;
const ll inf = 1e18 + 7;

ll F[dd * 4], S[dd * 4];

void up(int v, int l, int r, int c, int b) {
	if (l == r) {
		F[v] += b;
		S[v] += 1ll * c * b;
		return;
	}
	int s = (l + r) / 2;
	if (c <= s) {
		up(v * 2, l, s, c, b);
	}
	else {
		up(v * 2 + 1, s + 1, r, c, b);
	}
	F[v] = F[v * 2] + F[v * 2 + 1];
	S[v] = S[v * 2] + S[v * 2 + 1];
}

ll get(int v, int l, int r, ll sum) {
	if (l == r) {
		return sum * l;
	}
	int s = (l + r) / 2;
	if (sum >= F[v * 2 + 1]) {
		return S[v * 2 + 1] + get(v * 2, l, s, sum - F[v * 2 + 1]);
	}
	return get(v * 2 + 1, s + 1, r, sum);
}

int main() {
	if (_ijps) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	else {
		freopen(name".in", "r", stdin);
		freopen(name".out", "w", stdout);
	}

	vector<pair<int, pair<int, int> > > T;
	int n, m;
	ll p;
	cin >> n >> m >> p;
	ll res = 0;
	forn(i, n) {
		int x, a;
		scanf("%d%d", &x, &a);
		T.push_back(mk(x, mk(infi, a)));
	}
	forn(i, m) {
		int x, a, c;
		scanf("%d%d%d", &x, &a, &c);
		T.push_back(mk(x, mk(a, c)));
	}
	sort(T.begin(), T.end());
	ll suma, sumb;
	suma = sumb = 0;
	forn(i, T.size()) {
		if (T[i].second.first == infi) {
			suma += T[i].second.second;
		}
		else {
			sumb += T[i].second.first;
			up(1, 0, dd - 1, T[i].second.second, T[i].second.first);
		}
		ll t = get(1, 0, dd - 1, min(suma, sumb));
		ll s = t - T[i].first * p;
		res = max(res, s);
	}
	cout << res;
}