#include <bits/stdc++.h>
using namespace std;
struct rob {
  long long c, f;
};
bool porownanie(rob a, rob b) {
  if (a.f < b.f) return true;
  return false;
}
long long mini(long long a, long long b) {
  if (a < b) return a;
  return b;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n, d, s;
  cin >> n >> d >> s;
  vector<rob> a, A;
  vector<rob> b, B;
  for (int i = 0; i < n; ++i) {
    long long c, f, l;
    cin >> c >> f >> l;
    if (c != 0) {
      if (l >= d)
        A.push_back({c, f});
      else
        a.push_back({c, f});
    } else {
      if (l >= d)
        B.push_back({c, f});
      else
        b.push_back({c, f});
    }
  }
  sort(A.begin(), A.end(), porownanie);
  sort(B.begin(), B.end(), porownanie);
  reverse(A.begin(), A.end());
  A.push_back({-1, -1});
  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  B.push_back({-1, -1});
  reverse(B.begin(), B.end());
  vector<long long> prefAf(A.size(), 0);
  for (int i = 1; i < A.size(); ++i) prefAf[i] = prefAf[i - 1] + A[i].f;
  vector<long long> prefBf(B.size(), 0);
  for (int i = 1; i < B.size(); ++i) prefBf[i] = prefBf[i - 1] + B[i].f;
  long long ilewych = 0;
  for (int i = 1; i < A.size(); ++i) ilewych += A[i].c;
  for (int i = 0; i < a.size(); ++i) ilewych += a[i].c;
  long long odpil = 0, odpf = 1000000000000000000;
  int P = A.size() - 1;
  int wszA = A.size() - 1;
  int wsza = a.size();
  int wszB = B.size() - 1;
  int wszb = b.size();
  for (long long ileB = 0; ileB <= wszB; ++ileB) {
    if (prefBf[ileB] > s) continue;
    long long resztaf = s - prefBf[ileB];
    long long ilef = prefBf[ileB];
    while (P > 0 && prefAf[P] > resztaf) --P;
    long long ilemoge = ilewych - (wsza + wszA) + P;
    long long ilewezme = mini(ilemoge, wszb + wszB - ileB);
    ilef += prefAf[P];
    if (P > 0 && wszb + wszB - ileB < ilemoge) {
      long long nadmiardrzew = mini(ilemoge - (wszb + wszB - ileB), P - 1);
      ilef -= prefAf[P] - prefAf[P - nadmiardrzew];
    }
    int nowe;
    if (P != 0)
      nowe = ileB + (wsza + wszA) + ilewezme;
    else
      nowe = ileB;
    if (odpil < nowe || (odpil == nowe && ilef < odpf)) {
      odpil = nowe;
      odpf = ilef;
    }
  }
  cout << odpil << " " << odpf;
  return 0;
}
