stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

inline void boost(){ 

	ios_base::sync_with_stdio(0); 

	cin.tie(0); 

}



int f[90001];

int main(){

	boost();

	int h,w,d;

	cin>>h>>w>>d;

	map <int, pair <int, int> >adr;

	for(int i=1; i<=h; i++){

		for(int j=1; j<=w; j++){

			int x;

			cin>>x;

			adr[x].first = i;

			adr[x].second = j;

		}

	}

	for(int i=1; i<=h*w; i++){

			if( i <= d)

				f[i] = 0;

			else{

				f[i] = f[i-d] + abs(adr[i].first - adr[i-d].first) + abs(adr[i].second - adr[i-d].second);

			}

	}

	int q;

	cin>>q;

	int z,y;

	vector <int> ans;

	for(int i=0; i<q; i++){

		cin>>z>>y;

		ans.push_back(f[y] - f[z]);

	}

	for(int i = 0 ; i<ans.size(); i++){

		cout<<ans[i]<<endl;

	}

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#define abs(x) ((x>0)?x:(-(x)))

int H,W,D,A;

int Q,L,R;

int px[90001] ,py [90001];

int d[90001];

int  main()

{

    scanf ("%d %d %d",&H,&W,&D);

    for(int i=0;i<H;i++){

        for(int j=0;j<W;j++){

            scanf ("%d",&A);

            px[A]=i,py[A]=j;

        }

    }

    for(int i=D+1;i<=H*W;i++){ 

        d[i]=d[i-D]+abs(px[i]-px[i-D])+ abs(py[i]-py[i-D]);

    } 

    scanf ("%d",&Q);

    while(Q--){ 

        scanf ("%d%d",&L,&R);

        printf ("%d\n",d[R]-d[L]);

    } 

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <algorithm>

using namespace std;

int n, h, a[100005], b[100005], ma, sb, ans;

int main() {

	int i;

	scanf("%d%d", &n, &h);

	for(i=0; i<n; i++) {

		scanf("%d%d", &a[i], &b[i]);

		ma = max(ma, a[i]);

	}

	sort(b, b+n);

	for(i=n-1; i>=0; i--) {

		ans++;

		h -= max(b[i], ma);

		if(h<=0) break;

	}

	if(h>0) {

		ans += (h+ma-1)/ma;

	}

	cout<<ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using namespace std;

int n, h, a, b[100005], ma, ans;

int main() {

	int i;

	scanf("%d%d", &n, &h);

	for(i=0; i<n; i++) {

		scanf("%d%d", &a, &b[i]);

		ma = max(ma, a);

	}

	sort(b, b+n);

	for(i=n-1; i>=0 && h>0; i--) {

		ans++;

		h -= max(b[i], ma);

	}

	if(h>0) ans += (h+ma-1)/ma;

	printf("%d", ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define Would

#define you

#define please



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);



	int N, H;

	cin >> N >> H;

	int a[100000] = {};

	int b[100000] = {};

	rep(i, N) {

		cin >> a[i] >> b[i];

	}



	sort(a, a + N);

	sort(b, b + N);



	int saidai = a[N - 1];



	int kaisuu = 0;

	rep(i, N) {

		if (b[N - i - 1] > saidai) {

			kaisuu++;

			H -= b[N - i - 1];

			if (H <= 0) break;

		}

	}

	

	if (H > 0) {

		kaisuu += H / saidai;

		if (H % saidai) kaisuu++;

	}

	co(kaisuu);

	Would you please return 0;

}

// Optimized solution to the same problem (faster):
//#include<bits/stdc++.h>

#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



void pakuri_sort(int N, int A[]) {

	const int b = 8;

	int tmp[100001];

	rep(k, 4) {

		int kazu[1 << b] = {}, kazu2[1 << b] = {};

		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];

		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];

		k++;

		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];

		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];

	}

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);



	int N = getint(), H = getint();

	int saidai = 0;

	int b[100000];

	rep(i, N) {

		saidai = max(saidai, getint());

		b[i] = getint();

	}



	pakuri_sort(N, b);



	int kaisuu = 0;

	rep(i, N) {

		if (b[N - i - 1] > saidai) {

			kaisuu++;

			H -= b[N - i - 1];

			if (H <= 0) break;

		}

	}



	if (H > 0) {

		kaisuu += (H + saidai - 1) / saidai;

	}

	printf("%d", kaisuu);



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define Would

#define you

#define please



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);



	int N, H;

	cin >> N >> H;

	int saidai = 0;

	int b[100000];

	rep(i, N) {

		int a;

		cin >> a >> b[i];

		saidai = max(saidai, a);

	}



	sort(b, b + N);



	int kaisuu = 0;

	rep(i, N) {

		if (b[N - i - 1] > saidai) {

			kaisuu++;

			H -= b[N - i - 1];

			if (H <= 0) break;

		}

	}



	if (H > 0) {

		kaisuu += (H + saidai - 1) / saidai;

	}

	co(kaisuu);



	Would you please return 0;

}

// Optimized solution to the same problem (faster):
//#include<bits/stdc++.h>

#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



void pakuri_sort(int N, int A[]) {

	const int b = 8;

	int tmp[100001];

	rep(k, 4) {

		int kazu[1 << b] = {}, kazu2[1 << b] = {};

		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];

		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];

		k++;

		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];

		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];

	}

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);



	int N = getint(), H = getint();

	int saidai = 0;

	int b[100000];

	rep(i, N) {

		saidai = max(saidai, getint());

		b[i] = getint();

	}



	pakuri_sort(N, b);



	int kaisuu = 0;

	rep(i, N) {

		if (b[N - i - 1] > saidai) {

			kaisuu++;

			H -= b[N - i - 1];

			if (H <= 0) break;

		}

	}



	if (H > 0) {

		kaisuu += (H + saidai - 1) / saidai;

	}

	printf("%d", kaisuu);



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// 基本テンプレート

 

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <string>

#include <cstring>

#include <deque>

#include <list>

#include <queue>

#include <stack>

#include <vector>

#include <utility>

#include <algorithm>

#include <map>

#include <set>

#include <complex>

#include <cmath>

#include <limits>

#include <cfloat>

#include <climits>

#include <ctime>

#include <cassert>

#include <numeric>

#include <fstream>

#include <functional>

using namespace std;

 

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)

#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

#define debug(...) fprintf(stderr, __VA_ARGS__)

#define int long long int

 

template<typename T> void chmax(T &a, T b) {a = max(a, b);}

template<typename T> void chmin(T &a, T b) {a = min(a, b);}

template<typename T> void chadd(T &a, T b) {a = a + b;}

 

typedef pair<int, int> pii;

typedef long long ll;

 

int dx[] = {0, 0, 1, -1};

int dy[] = {1, -1, 0, 0};

const ll INF = 1001001001001001LL;

const ll MOD = 1000000007LL;



int N, H;

int A[100010], B[100010];



int solve() {

    int rest = H, cnt = 0;

    int dam = A[0];

    rep(i,0,N) {

        if(dam > B[i]) break;

        rest -= B[i];

        cnt++;

        if(rest <= 0) return cnt;

    }



    cnt += (rest + dam - 1) / dam;

    return cnt;

}

 

signed main() {

    cin >> N >> H;

    rep(i,0,N) {

        cin >> A[i] >> B[i];

    }

    sort(A, A+N, greater<int>());

    sort(B, B+N, greater<int>());



    cout << solve() << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using namespace std;

using Int = long long int;





const Int INF = 1LL << 30;

const int S = 100000;

Int N, H;

Int A[S+10], B[S+10];



int main() {

    scanf("%lld%lld", &N, &H);

    for(int i=0; i<N; i++) {

        scanf("%lld%lld", &A[i], &B[i]);

    }

    sort(A, A+N);

    sort(B, B+N);

    reverse(A, A+N);

    reverse(B, B+N);



    Int ub = INF, lb = -1;

    while(ub - lb > 1) {

        Int mid = (ub + lb) / 2;



        Int HP = H, rest = mid;

        for(int i=0; i<N && HP>0 && rest>0 && B[i] >= A[0]; i++, rest--) {

            HP -= B[i];

        }



        bool ok = (HP <= 0);

        if(!ok) {

            Int ope = (HP + A[0] - 1) / A[0];

            ok |= (ope <= rest);

        }



        (ok ? ub : lb) = mid;

    }



    printf("%lld\n", ub);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main(){

  int n, h;

  int a[100001] = {};

  int b[100001] = {};

  cin >> n >> h;

  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];

  sort(b, b+n); sort(a, a+n);

  int sum = 0;;

  for(int i = n-1; i >= 0; i--){

    if(h <= 0 || b[i] < a[n-1]) break;

    h -= b[i]; sum++;

  }

  if(h > 0){

    sum += h / a[n-1];

    sum += (h % a[n-1] > 0) ? 1 : 0;

  }

  cout << sum << endl;

  return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define ll long long

#define p pair<int, int>

using namespace std;



int main() {

    int n;

    ll h;

    cin >> n >> h;

    vector<p> v;

    int ma = -1;

    for (int i = 0; i < n; i++) {

        int a, b;

        cin >> a >> b;

        v.push_back(p(b, a));

        ma = max(ma, a);

    }

    sort(v.begin(), v.end());

    reverse(v.begin(), v.end());

    int ans = 0;

    for (int i = 0; i < n; i++) {

        if (ma <= v[i].first) {

            h -= v[i].first;

            ans++;

        }

        if (ma > v[i].first || h <= 0) break;

    }

    if (h > 0) {

        ans += h / ma;

        if (h % ma != 0) ans++;

    }

    cout << ans << endl;

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdlib>

#include <iomanip>

#include <cmath>

#include <string>

#include <cstring>

#include <algorithm>

#include <vector>

#include <sstream>

#include <set>

#include <queue>

#include <stack>

#include <cctype>

#include <map>

#include <climits>

#include <bitset>

using namespace std;

#define MATH_PI 3.14159265358979323846

struct Knife{

	int iHurt;

	int iType=0;

}arrKnives[1000000];



bool cmp(Knife nifKnife1, Knife nifKnife2){

	return (nifKnife1.iHurt>nifKnife2.iHurt);

}



int main(){

	ios::sync_with_stdio(false);

	int n, iHP;

	register int i,c = 0;

	scanf("%d %d", &n, &iHP);

	for (i = 1; i <= n; ++i){

		scanf("%d", &arrKnives[c].iHurt);

		++c;

		arrKnives[c].iType = 1;

		scanf("%d", &arrKnives[c].iHurt);

		++c;

	}

	sort(arrKnives, arrKnives + c, cmp);

	int iSum = 0;

	for (i = 0; i<c; ++i){

		if (arrKnives[i].iType == 1){

			++iSum;

			iHP -= arrKnives[i].iHurt;

			if (iHP <= 0){

				printf("%d", iSum);

				break;

			}

		}

		else if (arrKnives[i].iType != 1){

			if (iHP%arrKnives[i].iHurt == 0)

				iSum += iHP / arrKnives[i].iHurt;

			else 

				iSum += iHP / arrKnives[i].iHurt + 1;

			printf("%d", iSum);

			break;

		}

	}

endapp:

	//system("pause > nul");

	return 0;

}

// Optimized solution to the same problem (faster):
 #include<iostream>

 #include<cstdio>

 #include<cmath>

 #include<algorithm>

 //#include<cstring>

 using namespace std;

 struct knife

 {

     int ai;

     bool f;

 }m[2000018];

 inline int read()

 {

   int p=0,f=1;char c=getchar();

   while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}

   while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}

   return f*p;}

 int N,H,ans;

 bool cmp(knife x,knife y)

 {

     return x.ai>y.ai;//返回伤害最大的刀 

 }

 int main()

 {

     N=read(),H=read();

     for(int i=1;i<=N;i++)

         m[i].ai=read(),

      m[i+N].ai=read(),

         m[i+N].f=true;

     //我们把每把刀看作是可以无限扔的和只能扔一次的两把刀，存进去 

     sort(m+1,m+1+N*2,cmp);//排序，便于取 

     int ans=0;           //ans最终答案

     for(int i=1;i<=2*N;i++)//枚举2*N把刀 

        {

          if(m[i].f)//接下来贪心，如果刀可以飞出去就废掉，同时加上伤害 

            {ans++;

             H-=m[i].ai;}

          else

             {

              int u=H%m[i].ai;

              //如果碰到第一把无限次飞而且伤害最高的就无限砍 

              ans+=H/m[i].ai;

              //一直砍到没血，记录ans+ 

              if(u)ans++;

            H=-1;

             }

           if(H<=0)

             {printf("%d",ans);

              return 0;}

             //如果怪物没血了就输出 

        }

 }

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<iomanip>

#include<cmath>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<set>

#include<map>

#include<queue>

#include<stack>

#include<vector>

#include<cctype>

#define szxb 1000010

#define GO goto endreturn;

using namespace std;

int n,m;

struct ele{int cut;bool fly;}a[szxb];

inline bool cmp(ele x,ele y){return (x.cut>y.cut);}

int main()

{

	scanf("%d%d",&n,&m);int now(0);

	for(register int i(1);i<=n;i++){scanf("%d",&a[now++].cut);a[now].fly=1;scanf("%d",&a[now++].cut);}

	//for(register int i(0);i<=now-2;i++){for(register int j(0);j<=now-i-1;j++){if(a[j].cut<a[j+1].cut){swap(a[j],a[j+1]);}}}

	sort(a,a+now,cmp);

	int ans(0);

	for(register int i(0);i<=now-1;i++){if(a[i].fly){ans++;m-=a[i].cut;if(m<=0){GO}}else{if(!(m%a[i].cut)){ans+=(m/a[i].cut);}else{ans+=((m/a[i].cut)+1);}GO;}}

	endreturn:

		printf("%d",ans);return putchar(10),0;

}

// Optimized solution to the same problem (faster):
#include<algorithm>

#include<cstdio>

using namespace std;

inline void in(int &s){

	s=0;char c=getchar();

	while(c<'0' || c>'9'){

		c=getchar();

	}

	while(c>='0' && c<='9'){

		s=(s<<1)+(s<<3)+c-'0';

		c=getchar();

	}

}

int n,m,z,ans;

long long sum;

bool ok=1;

struct xx{

	int a,b;

}s[200002];

int cmp(xx x,xx y){

	return x.a>y.a;

}

int main(){

	in(n);in(m);

	for(int i=0;i<n;++i){

		in(s[z++].a);s[z].b=1;in(s[z++].a);

	}

	sort(s,s+z,cmp);

	for(int i=0;i<z;++i){

		if(s[i].b){

			m-=s[i].a;++ans;

		}

		else{

			if(m%s[i].a==0) ans+=m/s[i].a;

			else ans+=m/s[i].a+1;

			printf("%d\n",ans);break;

		}

		if(m<1){

			printf("%d\n",ans);break;

		}

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
    #include<bits/stdc++.h>

     

    using namespace std;

     

    const int MaxN = 1e5 + 15;

     

    int n, h;

     

    pair<int, int> a[MaxN];

    long long c[MaxN];

     

    int main()

    {

        ios_base :: sync_with_stdio(false);

        cin.tie(NULL);

     

        cin >> n >> h;

     

        int mx = 0;

     

        for(int i = 1; i <= n; ++i)

        {

            cin >> a[i].second >> a[i].first;

            mx = max(mx, a[i].second);

        }

        sort(a + 1, a + n + 1);

        for(int i = n; i; --i)

            c[i] = c[i + 1] + a[i].first;

     

        long long ans = 1e9;

     

        for(int i = n + 1; i; --i)

        {

            if(c[i] >= h)

                ans = min(ans, n - i + 1ll);

            else

                ans = min(ans, n - i + 1 + (h - c[i]) / mx + ((h - c[i]) % mx ? 1 : 0));

        }

     

        cout << ans << '\n';

        return 0;

    }

// Optimized solution to the same problem (faster):
#include<algorithm>

#include<cstdio>

using namespace std;

inline void in(int &s){

	s=0;char c=getchar();

	while(c<'0' || c>'9'){

		c=getchar();

	}

	while(c>='0' && c<='9'){

		s=(s<<1)+(s<<3)+c-'0';

		c=getchar();

	}

}

int n,m,z,ans;

long long sum;

bool ok=1;

struct xx{

	int a,b;

}s[200002];

int cmp(xx x,xx y){

	return x.a>y.a;

}

int main(){

	in(n);in(m);

	for(int i=0;i<n;++i){

		in(s[z++].a);s[z].b=1;in(s[z++].a);

	}

	sort(s,s+z,cmp);

	for(int i=0;i<z;++i){

		if(s[i].b){

			m-=s[i].a;++ans;

		}

		else{

			if(m%s[i].a==0) ans+=m/s[i].a;

			else ans+=m/s[i].a+1;

			printf("%d\n",ans);break;

		}

		if(m<1){

			printf("%d\n",ans);break;

		}

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cmath>

#include <functional>

#include <algorithm>

 

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

#define REP(i, n) for (int i = 0; i < (n); i++)

#define ALL(a) (a).begin(), (a).end()

 

using namespace std;

 

int main() {

    int N, H, a[100000], b[100000];

    cin >> N >> H;

    REP(i, N) cin >> a[i] >> b[i];

 

    int a_max = *max_element(a, a + N);

    sort(b, b + N, greater<int>());

 

    int ans = 0, i = 0;

    while (H > 0) {

        if (b[i] > a_max) {

            H -= b[i];

            ans++;

        }

        else break;

        i++;

    }

    if (H <= 0) {

        cout << ans << endl;

        return 0;

    }

    ans += ceil((double)H / a_max);

    cout << ans << endl;

 

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>



using namespace std;



long long N, H;

long long b[100010], a = 0;



int main() {

  int i;

  scanf("%lld %lld", &N, &H);

  long long sum = 0;

  for (i = 0; i < N; i++) {

    long long k;

    scanf("%lld %lld", &k, &b[i]);

    a = max(a, k);

  }

  sort(b, b+N);

  /*for (i = 0; i < N; i++) {

    printf("a:%d b:%d", a[i], b[i]);

    }*/

  long long ans = 0;

  for (i = N-1; i >= 0 && b[i] > a; i--) {

    H -= b[i];

    ans += 1;

    if (H <= 0) {

      break;

    }

  }

  //printf("after_b:%d", ans);

  if (H >= 0) {

    long long num_a = H / a;

    ans += num_a;

    if (H % a > 0) {

      ans += 1;

    }

  }

  printf("%lld", ans);

  return 0;

}

  

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cmath>

#include <string>

#include <algorithm>

#include <set>

#include <vector>

#include <map>

#include <list>

#include <stack>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#define REP(i, n) for(i=0; i<n; i++)

#define REPR(i, n) for(i=n; i>=0; i--)

#define FOR(i, m, n) for(i=m; i<n; i++)

#define max(a, b) ((a)>(b) ? (a):(b))

#define min(a, b) ((a)<(b) ? (a):(b))

#define INF 10000000000

#define MOD 1000000007LL

#define MAX 100005

#define NIL -1

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

typedef pair<double, double> doup;



ll modpow(ll x, ll n) {

    ll res=1;

    while(n>0) {

        if(n&1) res=res*x%MOD;

        x=x*x%MOD;

        n>>=1;

    }

    return res;

}



int main(void) {

    ll N, H;

    P p[MAX];

    ll i, ans=0;

    vector<ll> v;

    cin >> N >> H;

    for(i=0; i<N; i++) {

        cin >> p[i].first >> p[i].second;

    }

    sort(p, p+N);

    

    for(i=0; i<N; i++) {

        if(p[N-1].first<=p[i].second) {

            v.push_back(p[i].second);

        }

    }

    sort(v.begin(), v.end());

    

    for(i=(ll)v.size()-1; i>=0; i--) {

        H-=v[i]; ans++;

        if(H<=0) {

            cout << ans << endl;

            return 0;

        }

    }

    

    while(H>0) {

        H-=p[N-1].first;

        ans++;

        if(H<=0) {

            cout << ans << endl;

            return 0;

        }

    }

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <cmath>

#include <string>

#include <algorithm>

#include <set>

#include <vector>

#include <map>

#include <list>

#include <stack>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <queue>

#define mkp(a, b) make_pair(a, b)

#define pb(t) push_back(t)

#define ft first

#define sc second

#define pt(num) cout << num << "\n"

#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD

#define max(a, b) ((a)>(b) ? (a):(b))

#define min(a, b) ((a)<(b) ? (a):(b))

#define chmax(a, b) (a<b ? a=b : 0)

#define chmin(a, b) (a>b ? a=b : 0)

#define INF 1000000000000000000

#define MOD 1000000007LL

#define MAX 101010

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

typedef map<ll, ll> Map;





int main(void) {

    ll N, H;

    cin >> N >> H;

    ll i;

    priority_queue<P> q;

    for(i=0; i<N; i++) {

        ll a, b;

        cin >> a >> b;

        q.push(P(a, 0));

        q.push(P(b, 1));

    }

    

    ll ans=0;

    while(H>0) {

        P f=q.top(); q.pop();

        ll u=f.ft;

        

        if(f.sc==1) {

            H-=u;

            ans++;

        }else {

            ans+=(H+u-1)/u;

            break;

        }

    }

    

    pt(ans);

    

}


// Fastest known solution for this problem: