#include <bits/stdc++.h>
using namespace std;
struct rec {
  int c, f, l;
} a[100010], b[100010];
int n, d, s, m, temp, now, ans, i, k, cnt, rest;
long long sum;
priority_queue<int> q;
bool operator<(rec a, rec b) {
  if (a.l >= d && b.l < d) return 1;
  if (a.l < d && b.l >= d) return 0;
  return a.f < b.f;
}
int main() {
  cin >> n >> d >> s;
  temp = s + 1, k = i;
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].c, &a[i].f, &a[i].l);
    if (a[i].c) {
      sum += a[i].c - 1;
      if (a[i].l >= d && a[i].f < temp) temp = a[i].f, k = i;
      ans++;
    } else
      b[++m] = a[i];
  }
  sum++;
  sort(b + 1, b + m + 1);
  cnt = 0;
  now = s;
  for (i = 1; i <= m; i++)
    if (b[i].l >= d && b[i].f <= now) now -= b[i].f, cnt++;
  rest = s - now;
  if (temp > s) {
    cout << cnt << ' ' << rest << endl;
    return 0;
  }
  now = s - temp;
  for (i = 1; i <= n; i++)
    if (a[i].c && a[i].l >= d && k != i) q.push(-a[i].f);
  if (sum > m) {
    cout << n << ' ' << temp << endl;
    return 0;
  }
  for (i = 1; i <= m; i++)
    if (b[i].l < d) {
      if (sum)
        sum--, ans++;
      else if (-q.top() <= now)
        now += q.top(), ans++, q.pop();
    } else {
      if (sum)
        sum--, ans++, q.push(-b[i].f);
      else if (-q.top() <= now && -q.top() <= b[i].f)
        now += q.top(), ans++, q.pop(), q.push(-b[i].f);
      else if (-q.top() > b[i].f && b[i].f <= now)
        now += b[i].f, ans++;
    }
  if (cnt > ans || cnt == ans && rest < s - now)
    ans = cnt;
  else
    rest = s - now;
  cout << ans << ' ' << s - now << endl;
  return 0;
}
