#include <bits/stdc++.h>
using namespace std;
int c[110000], f[110000], l[110000], a[110000], b[110000];
int main() {
  int n, s, d, i, j, cnt, tot, ans, cost, ca, cb, sum;
  scanf("%d%d%d", &n, &d, &s);
  for (i = 0; i < n; i++) scanf("%d%d%d", c + i, f + i, l + i);
  for (i = cnt = ca = cb = 0; i < n; i++) {
    cnt += c[i];
    cnt = min(cnt, n);
    if (l[i] < d) continue;
    if (c[i])
      a[ca++] = f[i];
    else
      b[cb++] = f[i];
  }
  sort(a, a + ca);
  sort(b, b + cb);
  for (j = sum = 0; j < cb; j++) {
    if (sum + b[j] > s) break;
    sum += b[j];
  }
  ans = j;
  cost = sum;
  for (i = tot = 0; i < ca; i++) {
    tot += a[i];
    if (tot > s) break;
    if (cnt + i + 1 >= n) {
      if (cnt + i + 1 > ans) {
        ans = cnt + i + 1;
        cost = tot;
      } else if (cnt + i + 1 == ans)
        cost = min(cost, tot);
      break;
    }
    while (j) {
      if (tot + sum <= s) break;
      sum -= b[j - 1];
      j--;
    }
    while (j && cnt + i + 1 + j > n) {
      sum -= b[j - 1];
      j--;
    }
    if (cnt + i + j + 1 > ans) {
      ans = cnt + i + j + 1;
      cost = tot + sum;
    } else if (cnt + i + j + 1 == ans)
      cost = min(cost, tot + sum);
  }
  ans = min(ans, n);
  printf("%d %d\n", ans, cost);
  return 0;
}
