#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const long long INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const long long mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long n, H, A, D, S;
vector<long long> h, a;
int main() {
  cin >> n >> H >> A >> D >> S;
  long long res = H, as = 0;
  h = a = vector<long long>(n);
  vector<pair<double, int> > b;
  for (int i = 0; i < n; i++) {
    long long d, s;
    cin >> h[i] >> a[i] >> d >> s;
    long long da = max(A - d, 0ll);
    if (!da) {
      cout << -1 << endl;
      return 0;
    }
    h[i] = (h[i] + da - 1) / da;
    a[i] = max(a[i] - D, 0ll);
    as += a[i];
    if (s < S) res -= a[i];
    if (a[i]) {
      b.push_back({(double)h[i] / a[i], i});
    }
  }
  if (H <= 0) {
    cout << -1 << endl;
    return 0;
  }
  sort(b.rbegin(), b.rend());
  int B = b.size();
  for (int i = 0; i < B; i++) {
    int I = b[i].second;
    if (res < as - a[I]) {
      cout << -1 << endl;
      return 0;
    }
    res -= as * h[I] - a[I];
    as -= a[I];
    if (res <= 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << H - res << endl;
}
