Language: C++

//
//  main.cpp
//  atcoder - flowers
//
//  Created by r on 6/2/19.
//  Copyright © 2019 r. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

long long N, h[200010], a[200010], dp[200010];
long long t[900100];

long long findmax(long long v, long long tl, long long tr, long long l, long long r) {
    if (l > r)
        return numeric_limits<long long>::min(); // check negative numbers
    if (l == tl && r == tr) {
        return t[v];
    }
    long long tm = (tl + tr) / 2;
    return max(findmax(v*2, tl, tm, l, min(r, tm)) ,findmax(v*2+1, tm+1, tr, max(l, tm+1), r));
}


void updatemax(long long v, long long tl, long long tr, long long pos, long long new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        long long tm = (tl + tr) / 2;
        if (pos <= tm)
            updatemax(v*2, tl, tm, pos, new_val);
        else
            updatemax(v*2+1, tm+1, tr, pos, new_val);
        t[v] = max(t[v*2], t[v*2+1]);
    }
}



int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (long long i = 0; i<N; i++) cin >> h[i];
    for (long long i = 0; i<N; i++) cin >> a[i];
    for (long long i = 0; i<N; i++) {
        dp[i] = a[i]+findmax(1, 1, N, 1, h[i]);
        updatemax(1, 1, N, h[i], dp[i]);
    }
    int best = 0;
    for (int i = 0; i<N; i++) {
        best = max(best, dp[i]);
    }
    cout << best << endl;
    return 0;
}





Compiler output:
a.cc: In function 'int main()':
a.cc:77:19: error: no matching function for call to 'max(int&, long long int&)'
   77 |         best = max(best, dp[i]);
      |                ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:9:
/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:77:19: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   77 |         best = max(best, dp[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,
                 from a.cc:10:
/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:77:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   77 |         best = max(best, dp[i]);
      |                ~~~^~~~~~~~~~~~~