#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d, s;
  cin >> n >> d >> s;
  vector<pair<long long, long long> > zero, nonzero, lastused;
  long long route = 0;
  long long usedfuel = 0;
  long long maxtake = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    long long c, f, l;
    cin >> c >> f >> l;
    if (c == 0)
      zero.push_back(pair<long long, long long>(f, l));
    else {
      nonzero.push_back(pair<long long, long long>(f, l));
      if (route == 0) route++;
      route += (c - 1);
    }
  }
  lastused = zero;
  sort((nonzero).begin(), (nonzero).end());
  sort((zero).begin(), (zero).end());
  if (nonzero.size() != 0) {
    for (int(i) = 0; (i) < (nonzero.size()); (i)++)
      if (nonzero[i].first <= s - usedfuel && nonzero[i].second >= d) {
        usedfuel += nonzero[i].first;
        maxtake += nonzero.size();
        for (int(j) = (i + 1); (j) < (nonzero.size()); (j)++)
          lastused.push_back(nonzero[j]);
        break;
      }
    if (maxtake != 0) maxtake = min(n, maxtake + route);
    sort((lastused).begin(), (lastused).end());
    for (int(i) = 0; (i) < (lastused.size()); (i)++)
      if (maxtake != n && lastused[i].first <= s - usedfuel &&
          lastused[i].second >= d) {
        maxtake++;
        usedfuel += lastused[i].first;
      }
  }
  long long tmaxtake = 0;
  long long tusedfuel = 0;
  for (int(i) = 0; (i) < (zero.size()); (i)++)
    if (zero[i].first <= s - tusedfuel && zero[i].second >= d) {
      tmaxtake++;
      tusedfuel += zero[i].first;
    }
  if (tmaxtake > maxtake) {
    maxtake = tmaxtake;
    usedfuel = tusedfuel;
  } else if (tmaxtake == maxtake)
    usedfuel = min(usedfuel, tusedfuel);
  if (maxtake == 0)
    cout << 0 << " " << 0 << endl;
  else
    cout << maxtake << " " << usedfuel << endl;
}
