For this Question: There are N line segments on the 2-D plane. The endpoints of the i<sup>th</sup> line segment are (0, i) and (1, P<sub>i</sub>). Now your task is to highlight all the line segments so that small Tono can analyze them properly. The cost of highlighting the i<sup>th</sup> line segment is C<sub>i</sub>. 

Now there is a catch, if you choose to highlight the k<sup>th</sup> line segment, <b>ALL</b> the line segments intersecting the k<sup>th</sup> line segment are also highlighted (there is no further propogation). You <b>CANNOT</b> choose a line segment that has already been highlighted.

Find the minimum cost of highlighting all the line segments.

Note: P is the permutation of the first N natural numbers.The first line of the input contains an integer N.
The second line of the input contains N integers, P<sub>1</sub>, P<sub>2</sub>,... , P<sub>N</sub>.
The third line of the input contains N integers, C<sub>1</sub>, C<sub>2</sub>,... , C<sub>N</sub>.

Constraints
1 <= N <= 100000
1 <= P<sub>i</sub> <= N (P is a permutation of first N natural numbers)
1 <= C<sub>i</sub> <= 20000Output a single integer, the minimum cost to highlight all the line segments.Sample Input
4
1 2 3 4
1 2 3 4

Sample Output
10

Explanation: You need to highlight all the line segments individually.

Sample Input
4
2 1 4 3
1 2 3 4

Sample Output
4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;

// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

const int N = 1e5 + 5;
const int SQN = 1 << 10;
const int SZ = (N / SQN) + 5;
int n;
int p[N];
int w[N];
int r[N];
int dp[N];
int dp2[N];
int stk[SZ][SQN];
int sz[SZ];

void update(int row , int col , int val){
    int where = col >> 10;
    while(sz[where] && p[stk[where][sz[where]]] < col){
        --sz[where];
    }
    stk[where][++sz[where]] = row;
    dp2[row] = val;
    for(int i = sz[where] - 1 ; i >= 1 ; --i){
        val = min(val , dp2[stk[where][i]] = min(dp[stk[where][i]] , val));
    }
}

int query(int row , int col){
    int mx = -1;
    int res = 2e9 + 9;
    for(int i = col - 1 ; i >= ((col >> 10) << 10) ; --i){
        int ro = r[i];
        if(ro < row){
            if(ro > mx){
                res = min(res , dp[ro]);
                mx = ro;
            }
        }
    }
    for(int block = (col >> 10) - 1 ; block >= 0 ; --block){
        if(sz[block] && stk[block][sz[block]] > mx){
            int l = 1;
            int r = sz[block];
            while(l < r){
                int mid = (l + r) >> 1;
                if(stk[block][mid] > mx){
                    r = mid;
                }
                else{
                    l = mid + 1;
                }
            }
            res = min(res , dp2[stk[block][l]]);
            mx = stk[block][sz[block]];
        }
    }
    return res;
}


signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    cin>>n;
    for(int i = 1 ; i <= n ; ++i){
        cin>>p[i];
        r[p[i]] = i;
    }
    for(int i = 1 ; i <= n ; ++i){
        cin>>w[i];
    }
    p[0] = 0;
    r[0] = 0;
    p[n + 1] = n + 1;
    r[n + 1] = n + 1;
    w[0] = 0;
    w[n + 1] = 0;
    dp[0] = 0;
    update(0 , 0 , 0);
    for(int i = 1 ; i <= n + 1 ; ++i){
        dp[i] = query(i , p[i]) + w[i];
        update(i , p[i] , dp[i]);
    }
    cout<<dp[n+1];
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?