#include <bits/stdc++.h>
using namespace std;
int ans = 0, first = 0, c, f, l;
vector<pair<int, int> > a;
int main() {
  int n, d, s, i, k, ld = 0;
  scanf("%d%d%d", &n, &d, &s);
  for (i = 0; i < n; i++) {
    scanf("%d%d%d", &c, &f, &l);
    if (l >= d) a.push_back(make_pair(f, c));
    ld = min(ld + c, n);
  }
  sort(a.begin(), a.end());
  int sum = 0, cnt = 0;
  for (i = 0; i < a.size(); i++) {
    if (sum + a[i].first > s) break;
    sum += a[i].first;
    cnt++;
  }
  for (i = 0; i < a.size(); i++)
    if (a[i].second != 0) break;
  if (i == a.size() || a[i].first > s) {
    printf("%d %d\n", cnt, sum);
    return 0;
  }
  ans = cnt;
  first = sum;
  sum = a[k = i].first;
  if (ans < min(ld + (cnt = 1), n) ||
      ans == min(ld + (cnt = 1), n) && sum < first)
    ans = min(ld + cnt, n), first = sum;
  for (i = 0; i < a.size(); i++) {
    if (i == k) continue;
    if (sum + a[i].first > s) break;
    sum += a[i].first;
    cnt++;
    if (ans < min(cnt + ld, n)) ans = min(cnt + ld, n), first = sum;
  }
  printf("%d %d\n", ans, first);
}
