#include <bits/stdc++.h>

using namespace std;
/*
bool comp(pair<int, int> lhs, pair<int, int> rhs){
    return lhs.second
}
*/
const int MAX = 5e5 + 10;
int n, m, p;
long long FUR, TOV;
pair<int, int> tor[MAX], fur[MAX];
struct event{
    bool classe;
    long long kolT;
    int coord;
    long long price;
    long long value;

};
bool operator< (event lhs, event rhs){
    if(lhs.coord == rhs.coord)
        return lhs.classe;
    return lhs.coord < rhs.coord;
}
bool operator!(event lhs){
    cerr << lhs.coord << ' ' << lhs.kolT << ' ' << lhs.classe << ' ' << lhs.price << ' ' << lhs.value << endl;
    return true;
}

multiset<pair<long long , long long> > helper, cpy;
vector<pair<long long , long long> > buff;
void casep0(){
    long long sumFUR = 0;
    long long sumTOR = 0;
    for(int i = 0; i < n; ++i){
        cin >> fur[i].first >> fur[i].second;
        sumFUR += fur[i].second;
    }
    for(int i = 0; i < n; ++i){
        cin >> tor[i].first >> tor[i].second;
        sumTOR += ((long long)tor[i].second) * tor[i].first;
    }

}

void secC(){
    freopen("fisher.in","r",stdin);
    freopen("fisher.out","w",stdout);
    int n, m, p;
    cin >> n >> m >> p;
    /*if(p == 0){
        casep0();
        return;
    }*/
    event q[n + m];
    memset(q, 0, sizeof(event) * (n + m));
    for(int i = 0; i < n; ++i){
        q[i].classe = true;
        cin >> q[i].coord >> q[i].kolT;
    }
    for(int i = 0; i < m; ++i){
        cin >> q[i + n].coord >> q[i + n].value >> q[i + n].price;
    }
    sort(q, q + n + m);
    long long ans = 0, tov, curr = 0;
    for(int i = 0; i < n + m; ++i){
        //!q[i];
        if(i < n + m - 1)q[i + 1].kolT += q[i].kolT;
        if(!q[i].classe)
        helper.insert(make_pair(-q[i].price, q[i].value));
        buff.clear();
        ans = 0;
        tov = q[i].kolT;
        if(p || (p == 0 && i == n + m - 1)){
            //cerr << (*helper.begin()).second << ' ' << (*helper.begin()).first << endl;
            while(!helper.empty() && tov > 0){

                //cerr << (*helper.begin()).second << ' ' << -(*helper.begin()).first << ' ';
                buff.push_back(*helper.begin());
                ans += min((*helper.begin()).second, tov) * -(*helper.begin()).first;
                //cerr << ans << endl;
                tov -= min((*helper.begin()).second, tov);
                helper.erase(helper.begin());
            }
        }
        for(int j = 0; j < buff.size(); ++j)helper.insert(buff[j]);
        //cerr << ans - q[i].coord * p << endl;
        curr = max(curr, ans - q[i].coord * p);
    }
    cout << curr;
}

void terminalCS(){
    //freopen("fisher.in","r",stdin);
    //freopen("fisher.out","w",stdout);

    cin >> n >> m >> p;
    long long sumFUR = 0;
    long long sumTOR = 0;
    for(int i = 0; i < n; ++i){
        cin >> fur[i].first >> fur[i].second;
        sumFUR += fur[i].second;
    }
    for(int i = 0; i < n; ++i){
        cin >> tor[i].first >> tor[i].second;
        sumTOR += ((long long)tor[i].second) * tor[i].first;
    }
    if(p == 0){
        cout << min(sumFUR, sumTOR);
        return ;
    }

}

void secA(){
    int n, s;
    cin >> n >> s;
    pair<int, int> p[n];
    for(int i = 0; i < n; ++i){
        cin >> p[i].second >> p[i].first;
    }
    multiset<int> obrezki;
    sort(p, p + n);
    long long ans = 0;
    for(int i = n - 1; i >= 0; --i){
       // cerr << "CYCLE1\n";
       //cerr << *obrezki.begin() << endl;
            while(s > 0 && !obrezki.empty() && -*obrezki.begin() >= p[i].first){
                --s;
                obrezki.erase(obrezki.begin());
            }
        if(s > 0 && s >= p[i].second / p[i].first){
            s -= (p[i].second / p[i].first);
            p[i].second -= p[i].first * (p[i].second / p[i].first);
            obrezki.insert(-p[i].second);
        }
        else{
            if(s > 0){
                p[i].second -= s * p[i].first;
                s = 0;
            }
            obrezki.insert(-p[i].second);
        }
    }
    while(s > 0 && !obrezki.empty()){
        obrezki.erase(obrezki.begin());
        --s;
    }
    while(!obrezki.empty()){
        ans -= *obrezki.begin();
        obrezki.erase(obrezki.begin());
    }
   // cerr << ans << endl;
    cout << ans << endl;
    return ;

}

void solvea(){
    int n, s;
    cin >> n >> s;
    pair<int, int> p[n];
    for(int i = 0; i < n; ++i){
        cin >> p[i].second >> p[i].first;
    }
    sort(p, p + n);
    long long ans = 0;
    for(int i = n - 1; i >= 0; --i){
//        cerr << p[i].first << ' ' << p[i].second << endl;
//        cerr << (p[i].second / p[i].first) << endl;

        if(s >= p[i].second / p[i].first){
            s -= (p[i].second / p[i].first);
            p[i].second -= p[i].first * (p[i].second / p[i].first);
            swap(p[i].first, p[i].second);
            if(s > 0 && i > 0 && p[i].first > p[i - 1].first){
                p[i].first = 0;
                --s;
            }
        }
        else{
            if(s > 0){
                p[i].second -= p[i].first * s;
                s = 0;
                swap(p[i].first, p[i].second);
            }
            else
                swap(p[i].first, p[i].second);
        }
    }
    sort(p, p + n);
    int u = n - 1;
    while(s > 0){
        --u;
        --s;
    }
    for(;u >= 0; --u){
        ans += p[u].first;
    }
    cout << ans << endl;
    return ;
}

int main(){
/*    freopen("castle.in","r",stdin);
    freopen("castle.out","w",stdout);
    secA();
*/
    secC();
    //terminalCS();
    return 0;
}
