#include <bits/stdc++.h>
using namespace std;
struct node {
  int c, f, l;
};
bool cmp(const node &a, const node &b) { return a.f < b.f; }
node a[100010], b[100010], c[100010];
int main() {
  int n, d, s;
  while (scanf("%d%d%d", &n, &d, &s) == 3) {
    for (int i = 0; i < n; i++) scanf("%d%d%d", &a[i].c, &a[i].f, &a[i].l);
    int cnt = 0, cnt1 = 0, cnt2 = 0;
    long long canride = 0;
    for (int i = 0; i < n; i++) {
      if (a[i].c == 0 && a[i].l >= d)
        b[cnt++] = a[i];
      else if (a[i].c != 0 && a[i].l >= d)
        c[cnt1++] = a[i];
      if (a[i].c != 0) {
        cnt2++;
        canride += a[i].c;
      }
    }
    sort(b, b + cnt, cmp);
    int sum = 0, ans = -1;
    for (int i = 0; i < cnt; i++) {
      if (sum <= s - b[i].f)
        sum += b[i].f;
      else {
        ans = i;
        break;
      }
    }
    if (ans == -1 && sum <= s) ans = cnt;
    if (cnt1 == 0) {
      printf("%d %d\n", ans, sum);
      continue;
    }
    sort(c, c + cnt1, cmp);
    for (int i = 1; i < cnt1; i++) b[i - 1 + cnt] = c[i];
    cnt += cnt1 - 1;
    sort(b, b + cnt, cmp);
    int total = 0;
    for (int i = 0; i <= cnt; i++) {
      int less = s - total;
      if (less >= c[0].f) {
        int tans = min((long long)n, i + canride + 1);
        int tsum = c[0].f + total;
        if (tans > ans) {
          ans = tans;
          sum = tsum;
        } else if (tans == ans && tsum < sum) {
          sum = tsum;
        }
      }
      if (total <= s - b[i].f)
        total += b[i].f;
      else
        break;
    }
    printf("%d %d\n", ans, sum);
  }
  return 0;
}
