#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 100000;
int n, d, s, c[kMaxN], f[kMaxN], l[kMaxN];
pair<int, int> ans;
void Update(int first, int second) {
  if (first > ans.first)
    ans = make_pair(first, second);
  else if (first == ans.first)
    ans.second = min(ans.second, second);
}
namespace work0 {
int arr[kMaxN], cnt;
void Run() {
  for (int i = 0; i < n; ++i)
    if (c[i] == 0 && l[i] >= d) arr[cnt++] = f[i];
  sort(arr, arr + cnt);
  int first = 0, second = 0;
  for (int i = 0; i < cnt; ++i) {
    ++first, second += arr[i];
    if (second > s) break;
    Update(first, second);
  }
}
}  // namespace work0
namespace work1 {
int arr0[kMaxN], cnt0;
int arr1[kMaxN], cnt1;
void Run() {
  int can_carry = 0;
  for (int i = 0; i < n; ++i) can_carry = min(n, can_carry + c[i]);
  for (int i = 0; i < n; ++i)
    if (l[i] >= d) {
      if (c[i] == 0)
        arr0[cnt0++] = f[i];
      else
        arr1[cnt1++] = f[i];
    }
  sort(arr0, arr0 + cnt0);
  sort(arr1, arr1 + cnt1);
  if (!cnt1 || arr1[0] > s) return;
  int it0 = 0, it1 = 1;
  int second = arr1[0];
  for (;;) {
    int first = min(n, it0 + it1 + can_carry);
    Update(first, second);
    if (it0 == cnt0 && it1 == cnt1) break;
    if (it0 < cnt0 && (it1 == cnt1 || arr0[it0] < arr1[it1]))
      second += arr0[it0++];
    else
      second += arr1[it1++];
    if (second > s) break;
  }
}
}  // namespace work1
int main() {
  scanf("%d%d%d", &n, &d, &s);
  for (int i = 0; i < n; ++i) scanf("%d%d%d", &c[i], &f[i], &l[i]);
  work0::Run();
  work1::Run();
  printf("%d %d\n", ans.first, ans.second);
  return 0;
}
