Language: C++

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding Space*/
map<ll,int> m; //  nowh, p
int ans = 0;
int main(){
  int n; cin >> n;
  vector<tii> v(n);
  m[0] = 0;
  rep(i,n){
    int h,p; cin >> h >> p;
    v[i] = tii{p,h};
  }
  sort(ALL(v));
  rep(i,n){
    int h,p; tie(p,h) = v[i];
    vector<tuple<ll,int>> pv; //push vector
    for(auto j : m){
      if(j.FST <= h)
        pv.pb(tuple<ll,int>{(ll)j.FST+p,j.SEC+1});
    }
    for(auto j: pv){
      ll nh,np; tie(nh,np) = j;
      
      auto itr = m.lower_bound(nh);
      itr--;
      //DEB; SHOW(nh,np); SHOW((*itr).FST,(*itr).SEC);
      if((*itr).FST <= nh && (*itr).SEC < np){
        m[nh] = max(m[nh],np);
      }
    }
  }
  for(auto i:m)
    ans = max(ans,i.SEC);
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:20: error: no matching function for call to 'max(std::map<long long int, int>::mapped_type&, ll&)'
   51 |         m[nh] = max(m[nh],np);
      |                 ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:51:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   51 |         m[nh] = max(m[nh],np);
      |                 ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:51:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   51 |         m[nh] = max(m[nh],np);
      |                 ~~~^~~~~~~~~~