#include <iostream>
#include <c++/set>
#include <c++/tuple>

using namespace std;

int main() {
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    int n, m, p;
    cin >> n >> m >> p;
    if (p == 0)
    {
        int i;
        long long fish = 0;
        for (i = 0; i < n; i++)
        {
            int a, b;
            cin >> a >> b;
            fish += b;
        }
        multiset<pair<int, long long>> our;
        for (i = 0; i < m; i++)
        {
            int a, b, c;
            cin >> a >> b >> c;
            our.insert(make_pair(c, b));
        }
        long long res = 0;
        while (fish > 0 && !our.empty())
        {
            auto t = our.end();
            t--;
            auto c = *t;
            our.erase(t);
            int take = min(fish, c.second);
            fish -= take;
            res += take * c.first;
        }
        cout << res;
    }
}

/*
3 2 0
1 5
2 3
4 5
2 2 10
3 6 5

 */