Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_N = 2e5 + 50, INF = 1e15, MOD = 1e9 + 7;
ll N, hts[max_N], beauty[max_N], DP[max_N];

struct custom_comparator
{
    bool operator()(const ll &idx1, const ll &idx2)
    {
        return hts[idx1] < hts[idx2];
    }
};

ll solve()
{
    set<ll, custom_comparator> meaning;
    ll res = 0;
    DP[0] = beauty[0];
    meaning.insert(0);
    for (int i = 1; i < N; ++i)
    {
        DP[i] = beauty[i];
        auto it = meaning.upper_bound(i);
        if (it != meaning.begin())
        {
            it = prev(it);
            DP[i] = DP[*it] + beauty[i];
        }
        meaning.insert(i);
        it = meaning.upper_bound(i);
        while (it != meaning.end() && DP[*it] <= DP[i])
        {
            auto temp = next(it);
            meaning.erase(it);
            it = temp;
        }
    }
    res = *max_element(DP, DP + N);
    return res;
}

int main()
{
    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> hts[i];
    for (int i = 0; i < N; ++i)
        cin >> beauty[i];
    cout << solve() << "\n";
    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(_Const_Link_type) [with _Key = long long int; _Val = long long int; _KeyOfValue = std::_Identity<long long int>; _Compare = custom_comparator; _Alloc = std::allocator<long long int>; _Const_Link_type = const std::_Rb_tree_node<long long int>*]':
/usr/include/c++/14/bits/stl_tree.h:2116:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = long long int; _Val = long long int; _KeyOfValue = std::_Identity<long long int>; _Compare = custom_comparator; _Alloc = std::allocator<long long int>; key_type = long long int]'
 2116 |           __comp = _M_impl._M_key_compare(__k, _S_key(__x));
      |                                                ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:2169:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = long long int; _Key = long long int; _Val = long long int; _KeyOfValue = std::_Identity<long long int>; _Compare = custom_comparator; _Alloc = std::allocator<long long int>]'
 2169 |         = _M_get_insert_unique_pos(_KeyOfValue()(__v));
      |           ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:523:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(value_type&&) [with _Key = long long int; _Compare = custom_comparator; _Alloc = std::allocator<long long int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, custom_comparator, std::allocator<long long int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<long long int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::rebind<long long int>; typename _Alloc::value_type = long long int; value_type = long long int]'
  523 |           _M_t._M_insert_unique(std::move(__x));
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
a.cc:20:19:   required from here
   20 |     meaning.insert(0);
      |     ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_tree.h:768:15: error: static assertion failed: comparison object must be invocable as const
  768 |               is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:768:15: note: 'std::is_invocable_v<const custom_comparator&, const long long int&, const long long int&>' evaluates to false