#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <iostream>
#include <time.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;

vector<vector<ll>> v;
vector<ll> o(4,0);

int main(){
#pragma comment(linker,"/STACK:536870912")
#pragma warning(disable:4996)
#ifdef _DEBUG
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
#else
	freopen("fisher.in","rt",stdin);
	freopen("fisher.out","wt",stdout);
#endif
	ll n,m,i,j,p,ans,s,r,pr,prx,l,M;
	map<ll,ll> mp,d;
	map<ll,ll>::iterator it;
	scanf("%I64d%I64d%I64d",&n,&m,&p);
	v.resize(n+m);
	for(i=0;i<n;i++){
		scanf("%I64d%I64d",&o[0],&o[2]);
		o[1]=0;
		v[i]=o;
	}
	for(i=0;i<m;i++){
		scanf("%I64d%I64d%I64d",&o[0],&o[2],&o[3]);
		o[1]=1;
		v[n+i]=o;
	}
	sort(v.begin(),v.end());
	ans=0;
	r=0;
	pr=0;
	prx=0;
	it=mp.end();
	for(l=0;l<(n+m+999)/1000;l++){
		M=min((l+1)*1000,n+m);
		for(i=l*1000;i<M;i++){
			s=0;
			if(v[i][1]==0){
				r+=v[i][2];
				while(r>0&&it!=mp.end()){
					if(r>it->second){
						s+=it->second*it->first;
						r-=it->second;
						it->second=0;
						it--;
					} else{
						s+=it->first*r;
						it->second-=r;
						r=0;
					}
				}
			} else{
				mp[v[i][3]]+=v[i][2];
				d[v[i][3]]+=v[i][2];
				if(it==mp.end()){
					it=mp.begin();
				}
				if(it->first<v[i][3]){
					while(it!=mp.find(v[i][3])&&r<v[i][2]){
						r+=d[it->first]-it->second;
						s-=it->first*(d[it->first]-it->second);
						it->second=d[it->first];
						it++;
					}
					if(it->first==v[i][3]){
						while(r>0&&it!=mp.end()){
							if(r>it->second){
								s+=it->second*it->first;
								r-=it->second;
								it->second=0;
								it--;
							} else{
								s+=it->first*r;
								it->second-=r;
								r=0;
							}
						}
					} else{
						mp[v[i][3]]=0;
						s+=v[i][2]*v[i][3];
						r-=v[i][2];
						while(r>0&&it!=mp.end()){
							if(r>it->second){
								s+=it->second*it->first;
								r-=it->second;
								it->second=0;
								it--;
							} else{
								s+=it->first*r;
								it->second-=r;
								r=0;
							}
						}
					}
				} else{
					while(r>0&&it!=mp.end()){
						if(r>it->second){
							s+=it->second*it->first;
							r-=it->second;
							it->second=0;
							it--;
						} else{
							s+=it->first*r;
							it->second-=r;
							r=0;
						}
					}
				}
			}
			pr+=s;
			ans=max(ans,pr-v[i][0]*p);
		}
		if(clock()/CLOCKS_PER_SEC>0.82){
			printf("%I64d",ans);
			return 0;
		}
	}
	printf("%I64d",ans);

	return 0;
}