For this Question: Tono is on her mission to spread happiness everywhere. She has N close friends. She wants to make them stand in a line. She knows the happiness of the i<sup>th</sup> friend will be A[i] if the friend is standing among the first C[i] people in the line, else it would be B[i].

Find the maximum happiness that Tono can have in the line if she can arrange her friends in any order.The first line of the input contains an integer N.
The next N lines of the input contain three integers C[i], A[i], and B[i] denoting the parameters for the i<sup>th</sup> friend.

Constraints
1 <= N <= 100000
1 <= C[i] <= N
1 <= L[i], R[i] <= 10<sup>9</sup>Output the maximum happiness that Tono can achieve in the line.Sample Input
3
2 93 78
1 71 59
3 57 96

Sample Output
221

Explanation
The optimal order is [2, 1, 3]. 
The happiness of friend 1 = 93 (among the first 2 people), friend 2 = 71 (among the first 1 people), and friend 3 = 57 (among the first 3 people).

Sample Input
2
1 5 10
2 15 5

Sample Output
25, 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(ll 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;


const int N = 2e5+5;

// 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


void solve(){
    int n; cin>>n;
    vector<pii> f;
    vector<pii> b;
    int ans = 0;
    For(i, 0, n){
        int l, r, k; cin>>k>>l>>r;
        ans += min(l, r);
        if(l > r){
            f.pb({l-r, k});
        }
        else if(r > l){
            b.pb({r-l, k});
        }
    }
    sort(all(f)); reverse(all(f));
    sort(all(b)); reverse(all(b));
    set<int> s;
    For(i, 1, sz(f)+1){
        s.insert(i);
    }
    for(pii p: f){
        int ex = p.F;
        int pos = p.S;
        auto it = s.upper_bound(pos);
        if(it == s.begin())
            continue;
        it--;
        ans += ex;
        s.erase(it);
    }
    while(s.size()){
        s.erase(s.begin());
    }
    For(i, sz(f)+1, n+1){
        s.insert(i);
    }
    for(pii p: b){
        int ex = p.F;
        int pos = p.S;
        auto it = s.upper_bound(pos);
        if(it == s.end())
            continue;
        ans += ex;
        s.erase(it);
    }
    cout<<ans;
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1; 
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}

, In this Programming Language: C++, Now tell me if this Code is compilable or not?