#include <bits/stdc++.h>

using namespace std;

const long long INF=(long long) 1e17;

long long curpos,n,m,p,x,a,b,c,y,sum,curans,ans,type,cost,SS,pos,cnt,fx,fy;
multiset <pair <long long,long long> > s,S;
vector <pair <long long,long long> > f;
vector <pair <long long,pair <pair <long long,long long>,long long> > > v;

void update()
{
    //cout << "HI";
    long long kol=sum;
    long long newans=0;
    for(auto it=s.begin();it!=s.end();it++)
    {
        //cout << "HOHOH";
        if(sum==0) break;
        auto x=*it;
        x.first=-(x.first-INF);
        //cout << x.first << endl;
        newans+=min(kol,x.second)*x.first;
        kol-=min(kol,x.second);
    }
    curans+=newans;
}

void findans()
{
    for(auto it=S.begin();it!=S.end();it++)
    {
        if(SS==0) break;
        long long ccost=-(it->first-INF);
        ans+=ccost*min(SS,it->second);
        SS-=min(SS,it->second);
    }
}

int main()
{
    freopen("fisher.in","r",stdin);
    freopen("fisher.out","w",stdout);
    /*
    3 2 0
    1 5
    2 3
    4 5
    2 2 10
    3 6 5
    */
    /*
    2 1 100
    6 5
    100 4
    5 100 2000
    */
    cin >> n >> m >> p;
    for(int i=0;i<n;i++)
    {
        cin >> x >> a;
        if(i==0) fx=x;
        SS+=a;
        v.push_back(make_pair(x,make_pair(make_pair(0,0),a)));
    }
    for(int i=0;i<m;i++)
    {
        cin >> y >> b >> c;
        if(i==0) fy=y;
        f.push_back(make_pair(c,b));
        v.push_back(make_pair(y,make_pair(make_pair(1,c),b)));
    }
    sort(v.begin(),v.end());
    if(p==0)
    {
        for(int i=0;i<v.size();i++)
        {
            if(v[i].second.first.first==0) continue;
            cnt=v[i].second.second;
            cost = v[i].second.first.second;
            S.insert(make_pair(INF-cost,cnt));
        }
        findans();
        cout << ans;
        return 0;
    }
    if(fx>y)
    {
        ans=0;
        for(int i=m;i<v.size();i++)
        {
            if(i==m) curans-=p*fx; else curans-=p*(v[i].first-v[i-1].first);
            cnt=v[i].second.second;
            while(cnt>0&&curpos<m)
            {
                if(f[curpos].second>=cnt)
                {
                    cnt=0;
                    curans+=f[curpos].first*cnt;
                } else
                {
                    cnt-=f[curpos].second;
                    curans+=f[curpos].second*f[curpos].first;
                    curpos++;
                }
            }
            ans=max(ans,curans);
        }
        cout << ans;
        return 0;
    }
    /*if(fy>x)
    {

        return 0;
    }*/
    for(int i=0;i<v.size();i++)
    {
        type=v[i].second.first.first;
        pos=v[i].first;
        cnt=v[i].second.second;
        cost=v[i].second.first.second;
        //cout << type << " " << pos << " " << cnt << " " << cost << endl;
        //if(i==0) curans+=p*pos; else curans+=p*(pos-v[i-1].second.first);
        if(type==0) sum+=cnt;
        if(type==1) s.insert(make_pair(INF-cost,cnt));
        curans=0;
        update();
        //cout << i << " " << curans << endl;
        curans-=p*pos;// else curans-=p*(pos-v[i-1].first);
        ans=max(ans,curans);
    }
    cout << ans;
    return 0;
}
