Language: C++

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define Int long long
#define N 200200

Int dp[N];
Int tree[2*N+1];
int a[N],f[N];

void update(int x,int v,int node,int l,int r)
{
    if(l==r){
        tree[node]=v;return;
    }
    int mid = (l+r)/2;
    if(x<=mid)
    {
        update(x,v,(2*node),l,mid);
    }
    else
    {
        update(x,v,(2*node+1),mid+1,r);
    }
    tree[node]=max(tree[2*node],tree[2*node+1]);
}

int Q(int s,int e,int node,int l,int r)
{
    if(l>=s&&r<=e)return tree[node];
    else if(l>e||r<s)return 0;
    int mid = (l+r)/2;
    int x = Q(s,e,2*node,l,mid);
    int y = Q(s,e,2*node+1,mid+1,r);
    return max(x,y);
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m;
    cin>>n;
    for(int i = 1;i<=n;i++)cin>>a[i];
    for(int i = 1;i<=n;i++)cin>>f[i];
    for(int i = 1;i<=n;i++)
    {
        dp[a[i]]=Q(1,(a[i]-1),1,1,n)+f[i];

        update(a[i],dp[a[i]],1,1,n);
        //cout<<a[i]<< "  "<<Q(1,(a[i]),1,1,n)<<" "<<dp[a[i]]<<endl;

    }
    int ans=0;
    for(int i = 1;i<=n;i++)ans=max(ans,dp[a[i]]);
    //for(int i = 1;i<=(2*n-1);i++)cout<<i<<" "<<tree[i]<<endl;
    cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:35: error: no matching function for call to 'max(int&, long long int&)'
   55 |     for(int i = 1;i<=n;i++)ans=max(ans,dp[a[i]]);
      |                                ~~~^~~~~~~~~~~~~~
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:55:35: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   55 |     for(int i = 1;i<=n;i++)ans=max(ans,dp[a[i]]);
      |                                ~~~^~~~~~~~~~~~~~
/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:55:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   55 |     for(int i = 1;i<=n;i++)ans=max(ans,dp[a[i]]);
      |                                ~~~^~~~~~~~~~~~~~