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

using namespace std;

long long cnt = 0;
multiset<pair<long long, long long> > t, o;
vector<pair<long long, pair<long long, long long> > > a;


int main()
{
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	long long n, m, p;
	cin >> n >> m >> p;
	long long cur = 0, best = 0;
	for (long long i = 0; i < n; i++)
	{
		long long pos, x;
		cin >> pos >> x;
		a.push_back({pos, {-1, x}});
	}
	for (long long i = 0; i < m; i++)
	{
		long long pos, x, b;
		cin >> pos >> x >> b;
		a.push_back({pos, {x, b}});
	}
	sort(a.begin(), a.end());
	o.insert({0, 1e15 + 7});
	long long pos = 0;
	for (long long i = 0; i < (long long)a.size(); i++)
	{
		cur -= p * (a[i].first - pos);
		pos = a[i].first;
		if (a[i].second.first == -1)
		{
			long long add = a[i].second.second;
			while (add != 0)
			{
				long long curc = -o.begin()->first;
				long long curcnt = o.begin()->second;
				o.erase(o.begin());
				if (curcnt > add)
				{
					o.insert({-curc, curcnt - add});
					t.insert({curc, add});
					cur += curc * add;
					add = 0;
				}
				else
				{
					t.insert({curc, curcnt});
					cur += curc * curcnt;
					add -= curcnt;
				}
			}
		}
		else
		{
			long long addc = a[i].second.second;
			long long addcnt = a[i].second.first;
			long long nadd = 0;
			while (addcnt > 0 and t.size() and t.begin()->first < addcnt)
			{
				long long curc = t.begin()->first;
				long long curcnt = t.begin()->second;
				t.erase(t.begin());
				if (addcnt > curcnt)
				{
					o.insert({-curc, curcnt});
					addcnt -= curcnt;
					cur -= curc * curcnt;
					nadd = curcnt;
				}
				else
				{
					o.insert({-curc, addcnt});
					cur -= curc * addcnt;
					nadd += addcnt;
					addcnt = 0;
					if (curcnt - addcnt)
						t.insert({curc, curcnt - addcnt});
				}
			}
			cur += nadd * addc;
			if (nadd != 0)
				t.insert({addc, nadd});
			if (addcnt != 0)
				o.insert({-addc, addcnt});
		}
		best = max(cur, best);
	}
	cout << best << endl;
}
