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

using namespace std;
typedef long long ll;
struct bas
{
	int y, b, c;
};

int main()
{
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	ll n, m, p;
	cin >> n >> m >> p;
	vector<pair<ll, ll> >a(n), c(m);
	vector<bas>b(m);
	for (int i = 0; i < n; i++)
		cin >> a[i].first >> a[i].second;
	for (int i = 0; i < m; i++)
	{
		cin >> b[i].y >> b[i].b >> b[i].c;
		c[i] = make_pair(b[i].c, b[i].b);
	}
	if (p == 0)
	{
		ll ans = 0, ansa = 0;
		for (int i = 0; i < n; i++)
			ans += a[i].second;
		sort(c.rbegin(), c.rend());
		for (int i = 0; i < m && ans > 0; i++)
		{
			ll v = min(ans, c[i].second);
			ansa += v * c[i].first;
			ans -= v;
		}
		cout << ansa;
		return 0;
	}
	/*if (b[0].y > a[n - 1].first)
	{
		set<pair<int, int>>g;
		vector<int>ans;
		int d = 0;
		for (int i = 0; i < n; i++)
			d += a[i].second;
		for (int i = 0; i < m; i++)
		{
			if (g.empty())
			{
				g.insert(c[i]);
				ans[i] = c[i].first * min(c[i].second, d);
			}
				
			
		}
	}*/
	return 0;
}