#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
const ld INF = INFINITY;

#define s second
#define f first
#define pb push_back
#define m0(x) memset(x,0,sizeof(x))
#define myP pair<pair<ll,ll>,ll>


#define TASK "fisher"

ll n,m,p,xn,ym,fish = 0,x1 = -1,y1 = -1;
set<myP,greater<myP>> shop;
set<pair<ll,pair<ll,ll>>> shop_s3;
pair<ll,ll> base[100000];
myP shp[100000];
int q = 0;
ll jm = 0;

struct myS{
    int type;
    ll x,a,c;
};

myS C[100005];

bool cmp(myS a,myS b){
    if(a.x >= b.x) return false;
    return true;
}

ll sell(ll fish){
    ll res = 0;
    while(fish > 0 && q < m){
        ll buy = min(fish,shp[q].f.s);
        fish -= buy;
        shp[q].f.s -= buy;
        res += buy * shp[q].f.f;
        if(shp[q].f.s == 0) q++;
    }
    return res;
}

ll solve_p0(){
    ll res = 0;
    for(auto i : shop){
        ll sel = min(i.f.s,fish);
        res += sel * i.f.f;
        fish -= sel;
    }
    return res;
}
ll solve_2(){
    //cout<<"s2 "<<fish<<endl;
    int len = 0;
    for(auto i : shop)
        shp[len].f.f = i.f.f , shp[len].f.s  = i.f.s , shp[len].s = i.s,len++;

    ll res = 0,fish = 0;
    ll oil = 0,resm = 0;
    ll wsel = 0;

    for(int i=0;i<n;i++){
        fish = base[i].s;
        oil = base[i].f;
        wsel += sell(fish);
        //fish = 0;
        res = wsel - oil * p;
        resm = max(resm,res);
    }
    return resm;
}
ll solve_3(ll k){

    //
}
ll solve_4(){

    ll res = 0;
    ll resm = 0;

    for(int K=jm-1;K>=0;K--){
        res = solve_p0();
        ll X = C[K].x;
        res -= X*p;
        resm = max(res,resm);
        int type = C[K].type;
        if(type == 0){
            fish-=C[K].a;
        }else{
            myP pr;
            pr.f.f = C[K].c;
            pr.f.s = C[K].a;
            pr.s = C[K].x;
            shop.erase(pr);
        }
    }
    return resm;
}

int solve(){
    cin>>n>>m>>p;

    ll x,c,k = 0,a;


    for(int i=0;i<n;i++){
        cin>>x>>a;
        if(x1==-1) x1 = x;
        base[k].f = x;
        base[k].s = a;
        fish+=a;
        xn = x;
        ++k;
        C[jm].type = 0; C[jm].x = x; C[jm].a = a; C[jm].c = -1;
        ++jm;
    }
    for(int j=0;j<m;j++){
        cin>>x>>a>>c;
        if(y1==-1) y1 = x;
        myP pr;
        pr.f.f = c;
        pr.f.s = a;
        pr.s = x;
        shop.insert(pr);
        ym = x;
        C[jm].type = 1; C[jm].x = x; C[jm].a = a; C[jm].c = c;
        ++jm;
    }
   // cout<<jm<<endl;
    sort(C,C+jm,cmp);
    /*for(int i=0;i<jm;i++)
        cout<<C[i].type<<" "<<C[i].x<<" "<<C[i].a<<" "<<C[i].c<<endl;*/

    if(p==0) return cout<<solve_p0(),0;
    if(ym < x1) return cout<<solve_2(),0;
    //if(xn<y1) return cout<<solve_3(k-1),0;
    return cout<<solve_4(),0;

    return 0;
}

int main(){
    freopen(TASK".in","r",stdin);
    freopen(TASK".out","w",stdout);

    solve();
    //cout<<(ll)8500 * 8500 * 8500<<endl;
    return 0;
}
