#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

const int sz = 1e6;

struct p {
	long long a, b;
};

struct f {
	long long a, b, c;
};

p x[sz];
f y[sz];

bool comp(f a, f b) {
	return a.c > b.c;
}

struct shop {
	long long c, w, id;
	shop(long long a, long long b, long long i) {
		c = a;
		w = b;
		id = i;
	}
	const bool operator < (const shop arg) const {
		return c > arg.c || (c == arg.c && w > arg.w || w == arg.w && id > arg.id);
	}
};

struct point {
	long long pos, type, a, b;
};

point ar[sz];
long long sum[sz];

bool comp3(point a, point b) {
	return a.pos < b.pos || (a.pos == b.pos && a.type < b.type);
}

set <shop> s;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	int n, m;
	long long p;
	scanf("%d%d%lld", &n, &m, &p);
	if (p == 0) {
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			scanf("%lld%lld", &x[i].a, &x[i].b);
			sum += x[i].b;
		}
		for (int i = 0; i < m; i++) {
			scanf("%lld%lld%lld", &y[i].a, &y[i].b, &y[i].c);
		}
		sort(y, y + m, comp);
		long long res = 0;
		for (int i = 0; i < m && sum > 0; i++) {
			res += min(sum, y[i].b) * y[i].c;
			sum -= y[i].b;
		}
		printf("%lld", res);
	}
	else if (n <= 1000 && m <= 1000){
		for (int i = 0; i < n; i++) {
			scanf("%lld%lld", &ar[i].pos, &ar[i].a);
			ar[i].type = 1;
		}
		for (int i = n; i < n + m; i++) {
			scanf("%lld%lld%lld", &ar[i].pos, &ar[i].a, &ar[i].b);
			ar[i].type = 2;
		}
		sort(ar, ar + n + m, comp3);
		if (ar[0].type == 1) {
			sum[0] = ar[0].a;
		}
		else {
			s.insert(shop(ar[0].b, ar[0].a, 0));
		}
		long long res = 0;
		for (int i = 1; i < n + m; i++) {
			sum[i] = sum[i - 1];
			if (ar[i].type == 1) {
				sum[i] += ar[i].a;
			}
			else {
				s.insert(shop(ar[i].b, ar[i].a, i));
			}
			long long fish = sum[i], money = 0;
			for (auto it : s) {
				money += it.c * min(fish, it.w);
				fish -= min(fish, it.w);
			}
			res = max(res, money - ar[i].pos * p);
		}
		printf("%lld", res);
	}
	else {
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			scanf("%lld%lld", &x[i].a, &x[i].b);
			sum += x[i].b;
		}
		for (int i = 0; i < m; i++) {
			scanf("%lld%lld%lld", &y[i].a, &y[i].b, &y[i].c);
		}
		if (y[m - 1].a < x[0].a) {
			sort(y, y + m, comp);
			int it = 0;
			long long sum = 0;
			long long res = 0;
			for (int i = 0; i < n; i++) {
				sum += x[i].b;
				long long profit = 0;
				while (it < m && sum > 0) {
					long long v = min(y[it].b, sum);
					profit += v * y[it].c;
					sum -= v;
					y[it].b -= v;
					if (sum > 0) {
						it++;
					}
				}
				res = max(res, profit - p * x[i].a);
			}
			printf("%lld", res);
		}
		else {

		}
	}
	return 0;
}

