COFO::1217B Zmei Gorynich

Problem

Point

Design

Complexity

Code

#include<bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define sz(a) (int) a.size()
#define rep(i, a, b) for(int i=(a); i <(b); i++)
#define r_rep(i, a, b) for(int i=(a); i >(b); i--)
typedef long long ll;
using namespace std;

ll n, x;
void solve () {
    cin >> n >> x;
    vector<ll> d;
    vector<ll> diff; // d - h
    rep(i, 0, n) {
        ll a, b;
        cin >> a >> b;
        d.push_back(a);
        diff.push_back(a - b);
    }
    sort(d.rbegin(), d.rend());
    sort(diff.rbegin(), diff.rend());
    if (x <= d[0]) {
        cout <<"1\n";
        return;
    }
    if (diff[0] <= 0) {
        cout << "-1\n";
        return;
    }
    ll q = (x + diff[0] - 1) / diff[0];
    
    ll x2 = x - d[0];
    ll q2 = (x2 + diff[0] - 1) / diff[0] + 1;
    cout << min(q, q2) << '\n';
}
int main(){
    int tc; cin >> tc;
    while(tc--) {
        solve();
    }
        
    return 0;
}