#include <stdio.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iterator>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <assert.h>

using namespace std;

const int MAXN = 500000, SZ = 1001;

struct event {
	int pos, mx, cost, index;
};
vector<event> v;

bool cmp(const event& first, const event& second) {
	return first.pos < second.pos;
}

bool cmp1(const event& first, const event& second) {
	return first.cost > second.cost;
}

long long sell[MAXN + 1];

int main() {
	ios_base::sync_with_stdio(false);
	ifstream cin("fisher.in");
	ofstream cout("fisher.out");
	//return

	int n, m, p;
	cin >> n >> m >> p;
	assert(n <= MAXN && m <= MAXN);
	vector<int> xx, yy;
	for (int i = 0; i < n; i++) {
		int x, a;
		cin >> x >> a;
		v.push_back({ x, a });
		xx.push_back(x);
	}
	for (int i = 0; i < m; i++) {
		int y, b, c;
		cin >> y >> b >> c;
		v.push_back({ y, b, c });
		yy.push_back(y);
	}
	sort(v.begin(), v.end(), cmp);
	if (p == 0) {
		long long cnt = 0, ans = 0;
		for (int i = 0; i < (int)v.size(); i++)
			if (!v[i].cost)
				cnt += v[i].mx;
		sort(v.begin(), v.end(), cmp1);
		for (int i = 0; i < (int)v.size(); i++) {
			int mn = min((long long)v[i].mx, cnt);
			ans += 1LL * mn * v[i].cost;
			v[i].mx -= mn;
			cnt -= mn;
		}
		cout << ans << endl;
	}
	else if (yy.back() < xx[0]) {
		multiset<pair<int, int> > Port;
		long long ans = 0, res = 0;
		for (int i = 0; i < (int)v.size(); i++) {
			if (v[i].cost)
				Port.insert({ v[i].cost, v[i].mx });
			else {
				while (true) {
					if (Port.empty() || !v[i].mx)
						break;
					auto it = Port.end();
					it--;
					int cost = it->first;
					int cnt = it->second;
					Port.erase(it);
					int mn = min(cnt, v[i].mx);
					res += 1LL * mn * cost;
					v[i].mx -= mn;
					if (cnt > mn)
						Port.insert({ cost, cnt - mn });
				}
			}
			ans = max(ans, res - 1LL * p * v[i].pos);
		}
		cout << ans << endl;
	}
	else if (xx.back() < yy[0]) {
		long long cnt = 0, ans = 0, res = 0;
		multiset<pair<int, int> > Port;
		multiset<pair<int, pair<int, int> > > nw;
		for (int i = 0; i < (int)v.size(); i++) {
			if (!v[i].cost)
				cnt += v[i].mx;
			v[i].index = i;
		}
		sort(v.begin(), v.end(), cmp1);
		for (int i = 0; i < (int)v.size(); i++) {
			if (v[i].cost) {
				int mn = min((long long)v[i].mx, cnt);
				Port.insert({ v[i].cost, mn });
				res += 1LL * v[i].cost * mn;
				sell[v[i].index] = mn;
				if (mn < v[i].mx)
					nw.insert({ v[i].cost,{ v[i].mx - mn, v[i].index } });
				cnt -= mn;
			}
		}
		sort(v.begin(), v.end(), cmp);
		ans = max(0LL, res - 1LL * v.back().pos * p);
		for (int i = (int)v.size() - 1; i >= 0; i--) {
			if (v[i].cost) {
				auto it = Port.find({ v[i].cost, sell[i] });
				res -= 1LL * v[i].cost * sell[i];
				if (v[i].mx - sell[i])
					nw.erase({ v[i].cost,{ v[i].mx - sell[i], i } });
				Port.erase(it);
				cnt += sell[i];
				while (true) {
					if (!cnt || nw.empty())
						break;
					auto it = nw.end();
					it--;
					int can = it->second.first;
					int index = it->second.second;
					int cost = it->first;
					nw.erase(it);
					int mn = min(cnt, (long long)can);
					Port.erase(Port.find({ cost, sell[index] }));
					sell[index] += mn;
					Port.insert({ cost, sell[index] });
					res += 1LL * cost * mn;
					cnt -= mn;
					if (can > mn)
						nw.insert({ cost,{ can - mn, index } });
				}
				ans = max(ans, res - 1LL * p * v[i - 1].pos);
			}
		}
		cout << ans << endl;
	}
	else {
		long long ans = 0, cnt = 0, sum = 0, fish = 0, res = 0;
		multiset<pair<int, int> > Port;
		for (int i = 0; i < (int)v.size(); i++) {
			if (!v[i].cost) {
				cnt += v[i].mx;
				auto it = Port.end();
				if (!Port.empty()) {
					do {
						--it;
						int index = it->second;
						if (sell[index] < v[index].mx) {
							int mn = min(v[index].mx - sell[index], cnt);
							sell[index] += mn;
							cnt -= mn;
							res += 1LL * mn * v[index].cost;
						}
					} while (it != Port.begin());
				}
			}
			else {
				int temp = v[i].mx;
				int mn = min(cnt, (long long)v[i].mx);
				v[i].mx -= mn;
				cnt -= mn;
				sell[i] += mn;
				res += 1LL * mn * v[i].cost;
				for (auto it = Port.begin(); it != Port.end() && v[i].mx; it++) {
					if (it->first > v[i].cost)
						break;
					int index = it->second;
					int mn = min(sell[index], (long long)v[i].mx);
					sell[index] -= mn;
					sell[i] += mn;
					v[i].mx -= mn;
					res -= 1LL * mn * v[index].cost;
					res += 1LL * mn * v[i].cost;
				}
				v[i].mx = temp;
				Port.insert({ v[i].cost, i });
			}
			ans = max(ans, res - 1LL * v[i].pos * p);
		}
		cout << ans << endl;
	}
	return 0;
}