#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

const int maxN = 500000;


struct base
{
	int id;
	long long y;
	long long b, c;
	long long cf;

	base() {}

	base(int id, long long y, long long b, long long c) : id(id), y(y), b(b), c(c) { cf = 0; }
};



vector < pair<long long, pair<long long, long long> > > ev;
vector<base> bs;
int pos[maxN];
bool del[maxN];
long long profit = 0;

bool comp(base a, base b)
{
	return a.c < b.c;
}

int p = 0;

void rembs(int id)
{
	int i = pos[id];
	del[i] = true;
	long long transfer = bs[i].cf;
	profit -= bs[i].cf * bs[i].c;

	while (p < bs.size() && transfer > 0)
	{
		if (del[p])
		{
			p++;
			continue;
		}
		profit -= bs[p].cf * bs[p].c;
		transfer += bs[p].cf;
		profit += min(bs[p].b, transfer) * bs[p].c;
		transfer -= min(bs[p].b, transfer);
		p++;
	}
}

void remf(long long am)
{
	if (p == bs.size())
	{
		p--;
	}

	while (p >= 0 && am > 0)
	{
		if (del[p])
		{
			p--;
			continue;
		}
		profit -= min(am, bs[p].cf) * bs[p].c;
		long long delta = min(am, bs[p].cf);
		am -= delta;
		bs[p].cf -= delta;
		if (bs[p].cf == 0)
		{
			p--;
		}
	}
}


int main()
{
	//freopen("input.txt", "r", stdin);
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);

	long long n, m, cost;

	scanf("%I64d%I64d%I64d", &n, &m, &cost);

	long long tf = 0;

	for (int i = 0; i < n; i++)
	{
		long long x, a;
		scanf("%I64d%I64d", &x, &a);
		ev.push_back(make_pair(x, make_pair(0, a)));
		tf += a;
	}

	for (int i = 0; i < m; i++)
	{
		long long y, b, c;
		scanf("%I64d%I64d%I64d", &y, &b, &c);
		ev.push_back(make_pair(y, make_pair(b, i)));
		bs.push_back(base(i, y, b, c));
	}

	sort(ev.begin(), ev.end());

	sort(bs.rbegin(), bs.rend(), comp);



	for (int i = 0; i < bs.size(); i++)
	{
		pos[bs[i].id] = i;
	}

	for (int i = 0; i < bs.size(); i++)
	{
		if (tf >= bs[i].b)
		{
			bs[i].cf = bs[i].b;
			tf -= bs[i].b;
			profit += bs[i].b * bs[i].c;
			p++;
		}
		else
		{
			p = i;
			bs[i].cf += tf;
			profit += tf * bs[i].c;
			tf = 0;
			break;
		}
	}

	long long res = 0;

	for (int i = ev.size() - 1; i >= 0; i--)
	{
		long long ps = ev[i].first;
		long long b = ev[i].second.first, c = ev[i].second.second;
		long long fuel = ps * cost;
		res = max(res, profit - fuel);

		if (b == 0)
		{
			remf(c);
		}
		else
		{
			rembs(c);
		}
	}

	res = max(res, profit);
	cout << res;

    return 0;
}

