#include <bits/stdc++.h>
const double EPS = 1e-9;
const int INT_INF = 1 << 31 - 1;
const long long I64_INF = 1ll << 63 - 1ll;
const double PI = acos(-1.0);
using namespace std;
struct person {
  int c, first;
  person(int _c = 0, int _f = 0) {
    c = _c;
    first = _f;
  }
  friend bool operator<(const person& a, const person& b) {
    return a.first < b.first;
  }
};
int n, d, S;
vector<person> a;
vector<person> b;
vector<int> sumb;
int maxCNT = 0;
int minS = 0;
void upd(int a, int b) {
  if (a > maxCNT || a == maxCNT && b < minS) {
    maxCNT = a;
    minS = b;
  }
}
pair<int, int> go(int free, int second) {
  if (free >= (int)b.size()) return make_pair((int)b.size(), 0);
  if (b[0].first > second) return make_pair(free, 0);
  int r = (int)b.size() - free;
  int l = 0;
  while (l != r - 1) {
    int m = (l + r) >> 1;
    if (sumb[m] <= second)
      l = m;
    else
      r = m;
  }
  return make_pair(free + l + 1, sumb[l]);
}
int main() {
  scanf("%d%d%d", &n, &d, &S);
  for (int i = 0; i < (int)n; i++) {
    int c, first, l;
    scanf("%d%d%d", &c, &first, &l);
    if (l < d) first = S + 1;
    if (!c)
      b.push_back(person(c, first));
    else
      a.push_back(person(c, first));
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (!b.empty()) sumb.push_back(b[0].first);
  for (int i = 1; i < (int)b.size(); i++)
    if (*sumb.rbegin() > S)
      sumb.push_back(S + 1);
    else
      sumb.push_back(*sumb.rbegin() + b[i].first);
  pair<int, int> r = go(0, S);
  upd(r.first, r.second);
  int k = 0;
  int sum = 0;
  int Sum = 0;
  for (int i = 0; i < (int)a.size(); i++) {
    Sum += a[i].c;
    if (Sum > n + n) break;
  }
  for (int i = 0; i < (int)a.size(); i++) {
    k++;
    sum += a[i].first;
    if (sum > S) break;
    int x = Sum - (int)a.size() + k;
    pair<int, int> r = go(x, S - sum);
    upd((int)a.size() + r.first, sum + r.second);
  }
  printf("%d %d\n", maxCNT, minS);
  return 0;
}
