#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   vector<int> a;   vector<int> b;   vector<int> c;   vector<vector<int> > g;   int n, m, k;   int dp[5005][5005];   int solve(int at, int homens) {     if (at == n) {       return 0;     }     if (dp[at][homens] != -1) {       return dp[at][homens];     }     if (a[at] > homens) {       return dp[at][homens] = -INF;     }     int novoHomens = homens + b[at];     int resposta = solve(at + 1, novoHomens);     int valor = 0;     int quant = 0;     for (int viz : g[at]) {       quant++;       valor += viz;       if (novoHomens - quant >= 0) {         resposta = max(resposta, valor + solve(at + 1, novoHomens - quant));       }     }     return dp[at][homens] = resposta;   }   bool comp(int a, int b) { return c[a] > c[b]; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     a.resize(n);     b.resize(n);     c.resize(n);     for (int I = 0; I < n; I++) {       cin >> a[I] >> b[I] >> c[I];     }     g.resize(n);     int x, y;     vector<int> conexoes(n);     for (int I = 0; I < n; I++) {       conexoes[I] = I;     }     for (int I = 0; I < m; I++) {       cin >> x >> y;       x--;       y--;       conexoes[y] = max(conexoes[y], x);     }     for (int I = 0; I < n; I++) {       g[conexoes[I]].push_back(c[I]);     }     for (int I = 0; I < n; I++) {       sort(g[I].rbegin(), g[I].rend());     }     memset(dp, -1, sizeof(dp));     int resposta = solve(0, k);     if (resposta < 0) {       cout << -1 <<   n ;     } else {       cout << resposta <<   n ;     }     return 0;   }   