#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000;

ll A;
set<pair<ll, ll>> s;
vector<pair<ll, pair<ll, ll>>> v;

ll check() {
	if (s.empty()) return 0;
	set<pair<ll, ll>>::iterator it = s.end();
	ll a = A, res = 0;
	do {
		it--;
		if (a >= it->second) {
			res += it->second * it->first;
			a -= it->second;
		}
		else {
			res += a * it->first;
			a = 0;
		}
	} while (it != s.begin() && a != 0);
	return res;
}

int main() {
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	ll n, m, p;
	cin >> n >> m >> p;
	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		v.push_back(make_pair(x, make_pair(y, 0)));
	}
	for (int i = 0; i < m; i++) {
		ll x, y, z;
		cin >> x >> y >> z;
		v.push_back(make_pair(x, make_pair(y, z)));
	}
	sort(v.begin(), v.end());
	ll ans = 0;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].second.second == 0) A += v[i].second.first;
		else s.insert(make_pair(v[i].second.second, v[i].second.first));
		ans = max(ans, check() - p * v[i].first);
	}
	/*
	for (int i = m - 1; i >= 0 && A > 0; i--)
		if (A >= v[i].second) {
			A -= v[i].second;
			ans += v[i].first * v[i].second;
		}
		else {
			ans += A * v[i].first;
			A = 0;
		}*/
	cout << ans;
	return 0;
}