Language: C++

/*
    Author: aksayushx
*/
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
 
ll n;
vector<ll> h,a,dp;
ll high=pow(10,9);
vector<ll> segtree;
ll size=1;
void init(ll x)
{
    while(size<x)
    size*=2;
    segtree.assign(2*size,0);
}
void sets(ll i,ll v,ll x,ll lx,ll rx)
{
    if(rx-lx==1)
    {
        segtree[x]=v;
        return;
    }
    ll m=(lx+rx)/2;
    if(i<m)
        sets(i,v,2*x+1,lx,m);
    else
        sets(i,v,2*x+2,m,rx);
    segtree[x]=max(segtree[2*x+1],segtree[2*x+2]);
}
void setNum(ll i,ll v)
{
    sets(i,v,0,0,size);
}
ll getSu(ll l,ll r,ll x,ll lx,ll rx)
{
    if(l>=rx || lx>=r)
    return 0;
    if(lx>=l && rx<=r)
    return segtree[x];
    ll m=(lx+rx)/2;
    ll s1=getSu(l,r,2*x+1,lx,m);
    ll s2=getSu(l,r,2*x+2,m,rx);
    return max(s1,s2);
    
}
ll getMax(ll l, ll r)
{
    return getSu(l,r,0,0,size);
}

void aksayushx()
{
    cin>>n;
    h.resize(n);
    a.resize(n);
    init(n);
    for(ll i=0;i<n;i++) cin>>h[i];
    for(ll i=0;i<n;i++) cin>>a[i];
    vector<ll> dp(n+1,0);
    //dp[i] is the max beauty including flower i
    dp[0]=0;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        ll height=h[i];
        ll add=getMax(0,height);
        //get max beauty for heights 1...h[i]
        dp[height]=a[i];
        //for(ll j=1;j<h[i];j++)
        dp[h[i]]=max(dp[h[i]],a[i]+add);
        setNum(h[i],dp[h[i]]);
        ans=max(ans,dp[h[i]]);
        
    }
    
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--)
        aksayushx();
    return 0;
}


Compiler output:
a.cc: In function 'void init(ll)':
a.cc:22:11: error: reference to 'size' is ambiguous
   22 |     while(size<x)
      |           ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:4:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:19:4: note:                 'll size'
   19 | ll size=1;
      |    ^~~~
a.cc:23:5: error: reference to 'size' is ambiguous
   23 |     size*=2;
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:19:4: note:                 'll size'
   19 | ll size=1;
      |    ^~~~
a.cc:24:22: error: reference to 'size' is ambiguous
   24 |     segtree.assign(2*size,0);
      |                      ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:19:4: note:                 'll size'
   19 | ll size=1;
      |    ^~~~
a.cc: In function 'void setNum(ll, ll)':
a.cc:42:18: error: reference to 'size' is ambiguous
   42 |     sets(i,v,0,0,size);
      |                  ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:19:4: note:                 'll size'
   19 | ll size=1;
      |    ^~~~
a.cc: In function 'll getMax(ll, ll)':
a.cc:58:26: error: reference to 'size' is ambiguous
   58 |     return getSu(l,r,0,0,size);
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:19:4: note:                 'll size'
   19 | ll size=1;
      |    ^~~~