#include <fstream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

struct Token
{
	long long pos;
	long long Fnum, Snum, cost;
	long long SumNum;
	Token()
	{
		pos = Fnum = Snum = cost = SumNum = 0;
	}
};

map<long long, Token> arr;
map<long long, long long> sell;
vector<Token> Arr;

int main()
{
	ifstream fin("fisher.in");
	ofstream fout("fisher.out");
	long long n, m, p, ans = 0;
	fin >> n >> m >> p;
	for (int i = 0; i < n; i++)
	{
		long long pos, Fnum;
		fin >> pos >> Fnum;
		arr[pos].Fnum = Fnum;
		arr[pos].pos = pos;
	}
	for (int i = 0; i < n; i++)
	{
		long long pos, Snum, cost;
		fin >> pos >> Snum >> cost;
		arr[pos].Snum = Snum;
		arr[pos].cost = -cost;
		arr[pos].pos = pos;
	}
	for (auto it : arr)
		Arr.push_back(it.second);
	Arr[0].SumNum = Arr[0].Fnum;
	for (int i = 1; i < Arr.size(); i++)
		Arr[i].SumNum += Arr[i - 1].SumNum + Arr[i].Fnum;
	for (int i = 0; i < Arr.size(); i++)
	{
		long long FISH = Arr[i].SumNum;
		long long prof = p * Arr[i].pos;
		if (Arr[i].Snum)
			sell[Arr[i].cost] += Arr[i].Snum;
		if (i == Arr.size() - 1 || p > 0)
			for (auto it : sell)
			{
				prof += it.first * min(it.second, FISH);
				FISH -= min(it.second, FISH);
				if (!FISH)
					break;
			}
		ans = max(ans, -prof);
	}
	fout << ans;
	return 0;
}