#include <bits/stdc++.h>
using namespace std;
long long n, d, S;
long long C, bsiz;
long long dum;
vector<long long> bf1, bf2;
long long res1, res2;
int main() {
  scanf("%I64d %I64d %I64d", &n, &d, &S);
  while (n--) {
    long long c, f, l;
    scanf("%I64d %I64d %I64d", &c, &f, &l);
    if (c) {
      C += c;
      bsiz++;
      if (l >= d) bf1.push_back(f);
    } else {
      if (l < d)
        dum++;
      else
        bf2.push_back(f);
    }
  }
  sort(bf1.begin(), bf1.end());
  sort(bf2.begin(), bf2.end());
  long long used = 0;
  int i = 0;
  while (i < bf2.size() && used + bf2[i] <= S) used += bf2[i++];
  res1 = i;
  res2 = used;
  if (!bf1.empty() && bf1[0] <= S) {
    long long taken = bsiz;
    used = bf1[0];
    long long lft = C - bsiz + 1;
    long long take = min(lft, dum);
    taken += take;
    lft -= take;
    take = min(lft, (long long)bf2.size());
    taken += take;
    lft -= take;
    int r = bf2.size() - take;
    int i = 0, j = 1;
    while (i < r && j < bf1.size())
      if (bf1[j] < bf2[i] && used + bf1[j] <= S) {
        used += bf1[j];
        j++;
        r--;
        taken++;
      } else if (bf1[j] >= bf2[i] && used + bf2[i] <= S) {
        used += bf2[i];
        i++;
        taken++;
      } else
        break;
    while (i < r && used + bf2[i] <= S) {
      used += bf2[i++];
      taken++;
    }
    if (taken > res1 || taken == res1 && used < res2) {
      res1 = taken;
      res2 = used;
    }
  }
  printf("%I64d %I64d\n", res1, res2);
  return 0;
}
