#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define TASK "fisher"
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define mk make_pair
#define pk push_back
#define all(v) v.begin(), v.end()

const int MAXN = (int)5e5 + 7;
const int C = 550;

int solve();

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


struct event{
	int type, x, q, c;
	event(int _type = 0, int _x = 0, int _q = 0, int _c = 0) {
		type = _type, x = _x, q = _q, c = _c;
	}

	bool operator<(const event &e) const {
		if (x == e.x) {
			return type > e.type;
		}
		return x < e.x;
	}
};

struct price {
	ll q, c;
	bool operator<(const price &e) const{
		return c > e.c;
	}
};

int n, m, p;
event a[MAXN], b[MAXN];
event g[2 * MAXN];
ll prefsum[MAXN], prefprice[MAXN];

int blocks = 1, summar;
vector<price> pr[MAXN];
ll sum[MAXN], prc[MAXN];
price buf[MAXN];

void repref() {
	for1(i, blocks) {
		prefsum[i] = prefsum[i - 1] + sum[i];
		prefprice[i] = prefprice[i - 1] + prc[i];
	}
}

void recalc() {
	int cur = 0;
	for1(i, blocks) {
		forn(j, pr[i].size()) {
			buf[cur] = pr[i][j];
			cur++;
		}
		pr[i].clear();
		sum[i] = 0;
		prc[i] = 0;
	}

	if (!summar) return;
	int nblocks = summar / C;
	if (summar % C != 0) nblocks++;
	

	blocks = nblocks;
	cur = 0;
	for1(i, blocks) {
		pr[i].resize(min(C, summar - cur));
		forn(j, C) {
			if (cur < summar) {
				auto cop = buf[cur];
				ll q = cop.q, c = cop.c;
				pr[i][j] = cop;
				sum[i] += q;
				prc[i] += q * c;
				cur++;
			}
		}
	}
	repref();
}

void addto(int i, ll q, ll c) {
	pr[i].pk({ q, c });
	int cur = (int)pr[i].size() - 1;
	while (cur > 0 && pr[i][cur].c > pr[i][cur - 1].c) {
		swap(pr[i][cur], pr[i][cur - 1]);
		cur--;
	}
	sum[i] += q;
	prc[i] += q * c;
	repref();
}

void add(ll q, ll c) {
	summar++;
	for1(i, blocks) {
		if (!pr[i].empty() && pr[i].back().c < c) {
			addto(i, q, c);
			return;
		}
	}
	addto(blocks, q, c);
}

int findb(ll curq) {
	for1(i, blocks) {
		if (prefsum[i] > curq) {
			return i - 1;
		}
	}
	return blocks;
}

ll getans(ll curq, ll x) {
	//int cur = upper_bound(prefsum, prefsum + pr.size() + 1, curq) - prefsum - 1;
	int cur = findb(curq);
	ll dt = prefprice[cur];
	ll dq = curq - prefsum[cur];

	forn(i, pr[cur + 1].size()) {
		ll minim = min(dq, pr[cur + 1][i].q);
		dt += minim * pr[cur + 1][i].c;
		dq -= minim;
	}
	dt -= (ll)p * (ll)(x);
	return dt;
}

int solve() {
	cin >> n >> m >> p;
	forn(i, n) {
		scanf("%d%d", &a[i].x, &a[i].q);
		g[i] = event(0, a[i].x, a[i].q);
	}
	forn(i, m) {
		scanf("%d%d%d", &b[i].x, &b[i].q, &b[i].c);
		g[n + i] = event(1, b[i].x, b[i].q, b[i].c);
	}
	sort(g, g + n + m);

	ll curq = 0, answer = 0;
	forn(i, n + m) {
		auto e = g[i];
		int x = e.x, q = e.q, c = e.c;
		if (e.type == 0) {
			curq += q;
		}
		else {
			add(q, c);
		}
		ll dt = getans(curq, x);
		answer = max(answer, dt);

		if (i % C == 0) {
			recalc();
		}
	}
	cout << answer;
	return 0;
}