#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <cstdlib>
#include <vector>
#define ll long long
using namespace std;

const int MAXN = 1e5 + 111;

struct CC
{
	int y, b, c;
	CC() {}
	CC(int y, int b, int c) : y(y), b(b), c(c) {}
};

struct XX
{
	int x, a;
	XX() {}
	XX(int x, int a) : x(x), a(a) {}
};

int n, m, p;

vector <pair <int, int> > v;

XX x[MAXN];

CC c[MAXN];

set <CC> st;

int sum, cur;
ll cc;
ll vv;
ll ccc;
ll ans;

bool operator <(CC a, CC b)
{
	return a.c < b.c;
}

void solve1()
{
	ll sum = 0, ans = 0;
	for (int i = 0; i < n; i++)
		sum += x[i].a;
	sort(c + 0, c + m);
	for (int i = m - 1; i >= 0; i--)
	{
		if (sum >= c[i].b)
		{
			ans += (ll)c[i].b * c[i].c;
			sum -= c[i].b;
		}
		else
		{
			ans += sum * c[i].c;
			sum = 0;
		}
	}
	cout << ans;
	exit(0);
}

void solve2()
{
	sort(c + 0, c + m);
	int id = m - 1;
	int cur = 0;
	ll ans = 0;
	ll cc = 0;
	ll sum = 0;
	for (int i = 0; i < n; i++)
	{
		cc -= (ll)(x[i].x - cur) * p;
		cur = x[i].x;
		sum += x[i].a;
		if (id == -1)
			break;
		if (sum >= c[id].b)
		{
			cc += (ll)c[id].b * c[id].c;
			sum -= c[id].b;
			c[id].b = 0;
			id--;
		}
		else
		{
			cc += (ll)sum * c[id].c;
			c[id].b -= sum;
			sum = 0;
		}
		ans = max(ans, cc);
	}
	cout << ans;
	exit(0);
}


bool cmp(pair <int, int> a, pair <int, int> b)
{
	int xa;
	if (a.first)
		xa = c[a.second].y;
	else
		xa = x[a.second].x;
	int xb;
	if (b.first)
		xb = c[b.second].y;
	else
		xb = x[b.second].x;
	return xa < xb;
}

void go()
{
	while (!st.empty())
	{
		CC bb = *st.begin();
		if (vv - bb.b >= sum)
		{
			cc -= (ll)bb.b * bb.c;
			st.erase(bb);
		}
		else
			break;
	}
	ccc = 0;
	if (!st.empty())
	{
		CC bb = *st.begin();
		if (vv > sum)
			ccc = (vv - sum) * bb.c;
	}
}

void solve3()
{
	sort(v.begin(), v.end(), cmp);
	for (int i = 0; i < n + m; i++)
	{
		int tt = v[i].first;
		int xx;
		if (tt)
			xx = c[v[i].second].y;
		else
			xx = x[v[i].second].x;
		if (tt == 0)
		{
			cc -= (ll)(xx - cur) * p;
			cur = xx;
			sum += x[v[i].second].a;
		}
		else
		{
			cc -= (ll)(xx - cur) * p;
			cur = xx;
			st.insert(c[v[i].second]);
			cc += (ll)c[v[i].second].b * c[v[i].second].c;
			vv += c[v[i].second].b;
		}
		go();
		ans = max(ans, cc - ccc);
	}
	cout << ans;
}

int main()
{
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	scanf("%d %d %d", &n, &m, &p);
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d", &x[i].x, &x[i].a);
		v.push_back(make_pair(0, i));
	}
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d %d", &c[i].y, &c[i].b, &c[i].c);
		v.push_back(make_pair(1, i));
	}
	if (p == 0)
		solve1();
	if (c[m - 1].y < x[0].x)
		solve2();
	solve3();
	return 0;
}