Language: C++

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

struct ST {
    int a, b;
    ST(int _a, int _b) : a(_a), b(_b) {}
    bool operator<(const ST &an) {
        if(b == an.b) {
            return a < an.a;
        }
        return b > an.b;
    }
};

int dp[100001];

int main() {
    cout << fixed << setprecision(10);
    int N, M;
    cin >> N >> M;
    vector<ST> d(N);
    REP(i, N) { cin >> d[i].a >> d[i].b; }
    SORT(d);
    REP(i, N) { dp[i] = i / d[0].a * d[0].b; }
    FOR(j, 1, N) {
        for(int i = M; 0 <= i; i--) {
            if(dp[i - d[j].a] < dp[i]) {
                dp[i] = dp[i - d[j].a];
            } else {
                break;
            }
        }
    }
    cout << dp[M];
    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/bits/stl_tempbuf.h:61,
                 from /usr/include/c++/14/bits/stl_algo.h:69,
                 from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_construct.h: In instantiation of 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = ST; _Args = {}]':
/usr/include/c++/14/bits/stl_uninitialized.h:643:18:   required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = ST*; _Size = long unsigned int; bool _TrivialValueType = false]'
  643 |                 std::_Construct(std::__addressof(*__cur));
      |                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:712:20:   required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = ST*; _Size = long unsigned int]'
  710 |       return __uninitialized_default_n_1<__is_trivial(_ValueType)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  711 |                                          && __can_fill>::
      |                                          ~~~~~~~~~~~~~~~~
  712 |         __uninit_default_n(__first, __n);
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:779:44:   required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, allocator<_Tp>&) [with _ForwardIterator = ST*; _Size = long unsigned int; _Tp = ST]'
  779 |     { return std::__uninitialized_default_n(__first, __n); }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1720:36:   required from 'void std::vector<_Tp, _Alloc>::_M_default_initialize(size_type) [with _Tp = ST; _Alloc = std::allocator<ST>; size_type = long unsigned int]'
 1720 |           std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1721 |                                            _M_get_Tp_allocator());
      |                                            ~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:558:9:   required from 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = ST; _Alloc = std::allocator<ST>; size_type = long unsigned int; allocator_type = std::allocator<ST>]'
  558 |       { _M_default_initialize(__n); }
      |         ^~~~~~~~~~~~~~~~~~~~~
a.cc:40:19:   required from here
   40 |     vector<ST> d(N);
      |                   ^
/usr/include/c++/14/bits/stl_construct.h:119:7: error: no matching function for call to 'ST::ST()'
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:25:5: note: candidate: 'ST::ST(int, int)'
   25 |     ST(int _a, int _b) : a(_a), b(_b) {}
      |     ^~
a.cc:25:5: note:   candidate expects 2 arguments, 0 provided
a.cc:23:8: note: candidate: 'constexpr ST::ST(const ST&)'
   23 | struct ST {
      |        ^~
a.cc:23:8: note:   candidate expects 1 argument, 0 provided
a.cc:23:8: note: candidate: 'constexpr ST::ST(ST&&)'
a.cc:23:8: note:   candidate expects 1 argument, 0 provided