Language: C++

#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()

using namespace std;

void int_quicksort(int* sorted, int* data, long datanum);
void long_quicksort(long* sorted, long* data, long datanum);
void double_quicksort(double* sorted , double* data, long datanum);
int IntCompareA(const void* pElem1, const void* pElem2);
int DoubleCompareA(const void* pElem1, const void* pElem2);

//long a, b, c, d, i, j, k, n;


int main(){
//////////////////////////////////////////////////////

    long n, h;
    cin >> n >> h ;

    //long a[n] , b[n];
    vector<long> a(n);
    vector<long> b(n);
    for (int i = 0 ; i < n ; i ++ )
    {
        cin >> a[i] >> b[i];
    }




    long sumh = 0;
    long turn = 0;

    //解説
    //最後から順番に考えていく
    //最後，強い剣を全て投げた状態で終わるのが理想なので，強い剣から順番に投げていく
    //ただし,斬撃力の高い剣より打撃力の弱い剣は使わない．
    //（使わないものを除く）全ての剣を投げても相手が死なない場合は，最も斬撃力が強い剣を振ってダメージを与える

    //斬撃力の高い剣より打撃力の弱い剣は最初から使わないので
    long max_a = *max_element(a.begin(), b.begin());

    //投げる剣から
    vector<long> bs(b); //コピーコンストラクタを利用してbのコピーbsを作成
    sort(bs.begin(), bs.end());
    reverse(bs.begin(), bs.end());//降順に整理

    for(long x : bs)
    {
        if( x < max_a )//斬撃力の高い剣より打撃力の弱い剣の場合は何もしない
        {
            continue;
        }
        sumh += x;
        turn ++;
        if ( h <= sumh)
        {
            //戦闘終了
            cout << turn << endl;
            return 0;
        }
    }

    cout << "debug: " << sumh << endl;
    cout << "debug: " << turn << endl;

    //振ってダメージを与える
    while ( sumh < h )
    {
        sumh += max_a;
        turn ++;
    }
    //先頭終了
    cout << turn << endl;

    




    //long as[n], bs[n];
    //long_quicksort(as , a , n);
    //long_quicksort(bs , b , n);


    



    // long sum = 0;
    // for ( i = 0 ; i < n ; i ++ )
    // {
    //     sum += i;
    // }






    // cout <<      << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}



void int_quicksort(int* sorted , int* data, long datanum)
{
    memcpy( sorted , data , sizeof(int) * datanum );
    qsort(sorted, (size_t)datanum, (size_t)sizeof(int), IntCompareA );
}

void long_quicksort(long* sorted , long* data, long datanum)
{
    memcpy( sorted , data , sizeof(long) * datanum );
    qsort(sorted, (size_t)datanum, (size_t)sizeof(long), IntCompareA );
}

void double_quicksort(double* sorted , double* data, long datanum)
{
    memcpy( sorted , data , sizeof(double) * datanum );
    qsort( sorted, (size_t)datanum, (size_t)sizeof(double), DoubleCompareA );
}




// int 型要素を昇順ソートするときの比較関数
int IntCompareA(const void* pElem1, const void* pElem2)
{
    return *(const long*)pElem1 - *(const long*)pElem2;
}

// double 型要素を昇順ソートするときの比較関数
int DoubleCompareA(const void* pElem1, const void* pElem2)
{
    return *(const double*)pElem1 - *(const double*)pElem2;
}

Compiler output:
a.cc: In function 'void int_quicksort(int*, int*, long int)':
a.cc:115:5: error: 'memcpy' was not declared in this scope
  115 |     memcpy( sorted , data , sizeof(int) * datanum );
      |     ^~~~~~
a.cc:5:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include <algorithm> //sort()
  +++ |+#include <cstring>
    5 | 
a.cc: In function 'void long_quicksort(long int*, long int*, long int)':
a.cc:121:5: error: 'memcpy' was not declared in this scope
  121 |     memcpy( sorted , data , sizeof(long) * datanum );
      |     ^~~~~~
a.cc:121:5: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc: In function 'void double_quicksort(double*, double*, long int)':
a.cc:127:5: error: 'memcpy' was not declared in this scope
  127 |     memcpy( sorted , data , sizeof(double) * datanum );
      |     ^~~~~~
a.cc:127:5: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'