#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20, maxm = 1e9 + 7;
long long ans2, s2, n, s, d, sum, mn, ans, td, td2, RS;
vector<long long> robot, rt;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> d >> s;
  RS = s2 = s;
  mn = maxm;
  for (long long i = 0, c, f, l; i < n; i++) {
    cin >> c >> f >> l;
    if (c > 0) {
      sum += c;
      td++;
      if (l >= d) mn = min(mn, f), rt.push_back(f);
    } else if (l >= d)
      robot.push_back(f);
  }
  robot.push_back(maxm), rt.push_back(maxm);
  sort(robot.begin(), robot.end());
  sort(rt.begin(), rt.end());
  int j = robot.size() - 1;
  if (mn != maxm && s >= mn) {
    ans = min(sum + 1, n);
    s -= mn;
    int a = 1, b = 0;
    while (ans < n) {
      if (min(robot[b], rt[a]) > s) break;
      s -= min(robot[b], rt[a]);
      ans++;
      if (robot[b] < rt[a])
        b++;
      else
        a++;
    }
  }
  for (int i : robot)
    if (s2 >= i) s2 -= i, ans2++;
  if (ans2 > ans) ans = ans2, s = s2;
  if (ans2 == ans && s2 > s) ans = ans2, s = s2;
  cout << ans << " " << RS - s << endl;
}
