#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, s, d;
  cin >> n >> d >> s;
  vector<long long> vBase, vZero;
  pair<long long, long long> ans = {0, 0};
  long long addCap = 0, addCt = 0, subCt = 0, baseCap = 0;
  for (int i = 0; i < n; i++) {
    long long c, f, l;
    cin >> c >> f >> l;
    if (l >= d) {
      if (c) {
        vBase.push_back(f);
        baseCap += c - 1;
      } else {
        vZero.push_back(f);
      }
    } else {
      if (c) {
        addCap += c - 1;
        addCt++;
      } else {
        subCt++;
      }
    }
  }
  sort(vBase.begin(), vBase.end());
  sort(vZero.begin(), vZero.end());
  for (int i = 1; i < vZero.size(); i++) {
    vZero[i] += vZero[i - 1];
  }
  auto up = [&](long long ct, long long cost) {
    if (ct > ans.first || (ct == ans.first && cost < ans.second)) {
      ans = {ct, cost};
    }
  };
  auto it = upper_bound(vZero.begin(), vZero.end(), s);
  if (it != vZero.begin()) {
    long long ct = it - vZero.begin();
    it--;
    long long cost = *it;
    up(ct, cost);
  }
  int sz = vBase.size();
  long long fcost = 0;
  for (int i = 0; i < sz; i++) {
    fcost += vBase[i];
    long long cost = fcost;
    if (fcost > s) break;
    long long capt = baseCap + i + 1 + addCap;
    long long ct = sz + addCt;
    long long val = min(capt, subCt);
    capt -= val;
    ct += val;
    long long remS = s - fcost;
    if (capt >= vZero.size()) {
      ct += vZero.size();
    } else {
      ct += capt;
      int m = vZero.size() - capt;
      auto it = upper_bound(vZero.begin(), vZero.begin() + m, remS);
      if (it != vZero.begin()) {
        ct += it - vZero.begin();
        it--;
        cost += *it;
      }
    }
    up(ct, cost);
  }
  cout << ans.first << ' ' << ans.second;
  return 0;
}
