#include <bits/stdc++.h>
using namespace std;
int n, d, S;
vector<int> A, B;
int main() {
  scanf("%d %d %d", &n, &d, &S);
  long long sumC = 0;
  int a = 0, b = 0;
  for (int i = 1; i <= n; ++i) {
    int c, f, l;
    scanf("%d %d %d", &c, &f, &l);
    sumC += c;
    if (c > 0) {
      ++a;
      if (l >= d) A.push_back(f);
    } else {
      ++b;
      if (l >= d) B.push_back(f);
    }
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  long long sumA = 0, sumB = 0;
  int cntA = 0, cntB = 0;
  for (int i = 0; i < B.size(); ++i) sumB += B[i], ++cntB;
  int r = B.size() - 1;
  int bst_cnt = 0, bst_money = 0;
  for (int l = -1; l < (int)A.size(); ++l) {
    if (l >= 0) sumA += A[l], ++cntA;
    if (sumA > S) break;
    while (r >= 0 && (sumA + sumB > S || l >= 0 && sumC - a + cntA + cntB > b))
      sumB -= B[r], --cntB, --r;
    int tmp = cntB;
    if (l >= 0) tmp = min((long long)n, sumC + cntA + cntB);
    if (bst_cnt < tmp)
      bst_cnt = tmp, bst_money = sumA + sumB;
    else if (bst_cnt == tmp && bst_money > sumA + sumB)
      bst_money = sumA + sumB;
  }
  printf("%d %d\n", bst_cnt, bst_money);
  return 0;
}
