#include <bits/stdc++.h>
using namespace std;
namespace Work {
int c[100010], f[100010], l[100010];
int n, d, s;
void solve(FILE* fin, FILE* fout) {
  fscanf(fin, "%d%d%d", &n, &d, &s);
  for (int i = 0; i < n; i++) fscanf(fin, "%d%d%d", c + i, f + i, l + i);
  vector<int> a, b;
  a.clear();
  b.clear();
  for (int i = 0; i < n; i++)
    if (c[i] == 0 && l[i] >= d) a.push_back(f[i]);
  sort(a.begin(), a.end());
  int acnt = 0, acost = 0;
  int sum = 0;
  for (int i = 0; i < (int)a.size(); i++)
    if (sum + a[i] <= s) {
      sum += a[i];
      if (i + 1 > acnt || (i + 1 == acnt && sum < acost)) {
        acnt = i + 1;
        acost = sum;
      }
    }
  bool flag = false;
  for (int i = 0; i < n; i++)
    if (c[i] > 0 && f[i] <= s && l[i] >= d) flag = true;
  if (flag) {
    int carry = 0;
    for (int i = 0; i < n; i++) {
      carry += c[i];
      carry = min(carry, n);
    }
    a.clear();
    for (int i = 0; i < n; i++)
      if (l[i] >= d) {
        if (c[i] > 0)
          a.push_back(f[i]);
        else
          b.push_back(f[i]);
      }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int i = 1, j = 0;
    sum = a[0];
    while (true) {
      int cnt = min(n, carry + i + j);
      if (cnt > acnt || (cnt == acnt && sum < acost)) {
        acnt = cnt;
        acost = sum;
      }
      if (i == a.size() && j == b.size()) break;
      if (i < a.size() && (j == b.size() || a[i] < b[j])) {
        sum += a[i];
        i++;
      } else {
        sum += b[j];
        j++;
      }
      if (sum > s) break;
    }
  }
  fprintf(fout, "%d %d", acnt, acost);
}
}  // namespace Work
int main() {
  Work::solve(stdin, stdout);
  return 0;
}
