#include <bits/stdc++.h>
using namespace std;
struct node {
  long long have;
  long long need;
  long long dis;
} qlist1[100003], qlist2[100003];
int t1 = 0, t2 = 0;
int front[2] = {0}, rear[2];
bool operator<(const node &a, const node &b) { return a.need < b.need; }
int main() {
  int n, i, j;
  long long need, dis, t, tt, ttt, count = 1;
  scanf("%d%I64d%I64d", &n, &dis, &need);
  for (i = 0; i < n; i++) {
    scanf("%I64d%I64d%I64d", &t, &tt, &ttt);
    if (ttt < dis) tt = need + 1;
    if (t == 0) {
      qlist1[t1].have = t;
      qlist1[t1].need = tt;
      qlist1[t1++].dis = ttt;
    } else {
      count += t - 1;
      qlist2[t2].have = t;
      qlist2[t2].need = tt;
      qlist2[t2++].dis = ttt;
    }
  }
  sort(qlist1, qlist1 + t1);
  sort(qlist2, qlist2 + t2);
  rear[0] = t1 - 1;
  rear[1] = t2 - 1;
  long long tmp = need;
  int ans = 0;
  if (rear[1] > -1 && tmp >= qlist2[0].need) {
    tmp -= qlist2[0].need;
    ans = t2;
    if (count >= t1) {
      printf("%d %I64d\n", n, need - tmp);
      return 0;
    }
    ans += count;
    rear[0] -= count;
    front[1] = 1;
    while (front[0] <= rear[0]) {
      if (front[1] <= rear[1]) {
        if (qlist2[front[1]].need <= qlist1[front[0]].need &&
            tmp >= qlist2[front[1]].need) {
          tmp -= qlist2[front[1]++].need;
          rear[0]--;
        } else if (tmp >= qlist1[front[0]].need)
          tmp -= qlist1[front[0]++].need;
        else
          break;
      } else if (tmp >= qlist1[front[0]].need)
        tmp -= qlist1[front[0]++].need;
      else
        break;
      ans++;
    }
  }
  front[0] = 0;
  rear[0] = t1 - 1;
  int tmp_ans = 0;
  long long tmptmp = need;
  while (front[0] <= rear[0] && tmptmp >= qlist1[front[0]].need) {
    tmptmp -= qlist1[front[0]++].need;
    tmp_ans++;
  }
  if (tmp_ans > ans || (tmp_ans == ans && tmptmp > tmp))
    printf("%d %I64d\n", tmp_ans, need - tmptmp);
  else
    printf("%d %I64d\n", ans, need - tmp);
  return 0;
}
