Language: C++

/// 3:38 PM 24/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>

using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define VARIABLE_ERROR(x) cout << #x << " = " << x << endl;
#define CONTAINER_ERROR(v) cout << "{";for (auto &x:v) { cout << x << ','; }cout << "}" << endl;
#define PI 3.14159265358979323846
#define M 1000000007
#define INF 1e9;
typedef int ll;

void build(ll l, ll r, ll in, vector<ll> &v, vector<ll> &tree) {
    if (l > r) {
        return;
    }
    if (l == r) {
        tree[in] = v[l];
        return;
    }
    ll mid = (l + r) >> 1ll;
    build(l, mid, 2 * in + 1, v, tree);
    build(mid + 1, r, 2 * in + 2, v, tree);
    tree[in] = max(tree[2 * in + 1], tree[2 * in + 2]);
}

ll query(ll l, ll r, ll ql, ll qr, ll in, vector<ll> &tree) {
    if (l > qr || r < ql || l > r) {
        return -INF;
    }
    if (l >= ql && r <= qr) {
        return tree[in];
    }
    ll mid = (l + r) >> 1ll;
    ll left = query(l, mid, ql, qr, 2 * in + 1, tree);
    ll right = query(mid + 1, r, ql, qr, 2 * in + 2, tree);
    ll ans = max(left, right);
    return ans;
}

void update(ll l, ll r, ll index, ll in, vector<ll> &tree, vector<ll> &v) {
    if (l > r) {
        return;
    } else if (index < l || index > r) {
        return;
    } else if (l == r) {
        tree[in] = v[index];
        return;
    }
    ll mid = (l + r) >> 1;
    update(l, mid, index, 2 * in + 1, tree, v);
    update(mid + 1, r, index, 2 * in + 2, tree, v);
    tree[in] = max(tree[2 * in + 1], tree[2 * in + 2]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> h(n);
    vector<ll> a(n);
    for (auto &x:h) {
        cin >> x;
        x--;
    }
    for (auto &x:a) {
        cin >> x;
    }
    vector<ll> maxVal(n, -INF);
    vector<ll> dp(n);
    dp[0] = a[0];
    maxVal[h[0]] = a[0];
    vector<ll> tree(4 * n + 4);
    build(0, n - 1, 0, maxVal, tree);
    for (ll i = 1; i < n; i++) {
        ll mv = query(0, n - 1, 0, h[i] - 1, 0, tree);
        if (mv == -INF) {
            maxVal[h[i]] = a[i];
            update(0, n - 1, h[i], 0, tree, maxVal);
        } else {
            ll temp = mv + a[i];
            maxVal[h[i]] = a[i] + mv;
            update(0, n - 1, h[i], 0, tree, maxVal);
        }
    }
    ll ans = -INF;
    for (ll i = 0; i < n; i++) {
        ans = max(ans, maxVal[i]);
    }
    cout << ans;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:16: error: expected ')' before ';' token
   16 | #define INF 1e9;
      |                ^
a.cc:77:27: note: in expansion of macro 'INF'
   77 |     vector<ll> maxVal(n, -INF);
      |                           ^~~
a.cc:77:22: note: to match this '('
   77 |     vector<ll> maxVal(n, -INF);
      |                      ^
a.cc:77:30: error: expected primary-expression before ')' token
   77 |     vector<ll> maxVal(n, -INF);
      |                              ^
a.cc:85:23: error: expected primary-expression before ')' token
   85 |         if (mv == -INF) {
      |                       ^