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

multiset<pair<ll, ll>> s;
vector<pair<ll, ll>> ss;
ll A;

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

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
	return a.second > b.second;
}

ll check2() {
	ll a = A, res = 0;
	sort(ss.begin(), ss.end(), cmp);
	for (int i = 0; i < ss.size(); i++)
		if (a >= ss[i].second) {
			a -= ss[i].second;
			res += ss[i].first * ss[i].second;
		}
		else {
			res += a * ss[i].first;
			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;
	vector<pair<ll, pair<ll, ll>>> v(n + m);
	for (int i = 0; i < n; i++) {
		cin >> v[i].first >> v[i].second.first;
		if (v[i].second.first == 0)
			throw 1;
	}
	for (int i = n; i < n + m; i++) {
		cin >> v[i].first >> v[i].second.first >> v[i].second.second;
		if (v[i].second.first == 0 || v[i].second.second == 0)
			throw 1;
	}
	sort(v.begin(), v.end());
	ll ans = 0;
	s.insert(make_pair(0, 0));
	if (p == 0) {
		for (int i = 0; i < n + m; i++) {
			if (v[i].second.second) s.insert(make_pair(v[i].second.second, v[i].second.first));
			else A += v[i].second.first;
		}
		ans = max(ans, check());
		cout << ans;
		return 0;
	}

	/*if (p == 0) {
	for (int i = 0; i < v.size(); i++) {
	if (v[i].second.second) ss.push_back(make_pair(v[i].second.second, v[i].second.first));
	else A += v[i].second.first;
	}
	ans = max(ans, check2());
	cout << ans;
	return 0;
	}*/

	for (int i = 0; i < n + m; i++) {
		if (v[i].second.second) s.insert(make_pair(v[i].second.second, v[i].second.first));
		else A += v[i].second.first;
		ans = max(ans, check() - p * v[i].first);
	}
	cout << ans;
	return 0;
}