Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

ll const INF = ll(1e18);

struct Seq {
    int l;
    int r;
    ll c;
};

bool operator<(Seq const& lhs, Seq const& rhs) {
    if (lhs.l == rhs.l) {
        if (lhs.r == rhs.r) {
            return lhs.c < rhs.c;
        }
        return lhs.r < rhs.r;
    }
    return lhs.l < rhs.l;
}

struct RNGT {
    int nd;
    vector<ll> d;

    RNGT(int n) {
        nd = n;
        d.resize(nd * 4, INF);
    }

    void update(int qp, int val) {
        return __update(1, 0, nd-1, qp, val);
    }
    void __update(int p, int l, int r, int qp, int val) {
        if (qp<l || r<qp) return;
        if (l==r) {
            d[p] = min(d[p], val);
            return;
        }

        int mid = l + (r - l) / 2;
        __update(p * 2, l, mid, qp, val);
        __update(p * 2 + 1, mid + 1, r, qp, val);
        d[p] = min(d[p*2], d[p*2+1]);
    }

    ll query(int ql, int qr) {
        return __query(1, 0, nd-1, ql, qr);
    }
    ll __query(int p, int l, int r, int ql, int qr) {
        if (r<ql || qr<l) return INF;
        if (l == r) return d[p];

        int mid = l + (r-l)/2;
        return min(__query(p*2, l, mid, ql, qr), __query(p*2+1, mid+1, r, ql, qr));
    }
};

int main() {
    int n, m;
    cin >> n >> m;

    vector<Seq> vs;
    int l, r, c;
    for (int i = 0; i < m; ++i) {
        cin >> l >> r >> c;
        --l, --r;
        vs.push_back({l, r, c});
    }
    sort(vs.begin(), vs.end());

    RNGT segt(n);
    segt.update(0, 0);
    for (int i=0; i<m; ++i) {
        segt.update(vs[i].r, segt.query(vs[i].l, vs[i].r-1) + vs[i].c);
    }

    ll ans = segt.query(n - 1, n - 1);
    cout << (ans == INF ? -1 : ans) << endl;
}

Compiler output:
a.cc: In member function 'void RNGT::__update(int, int, int, int, int)':
a.cc:42:23: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int&)'
   42 |             d[p] = min(d[p], val);
      |                    ~~~^~~~~~~~~~~
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:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:42:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   42 |             d[p] = min(d[p], val);
      |                    ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:42:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |             d[p] = min(d[p], val);
      |                    ~~~^~~~~~~~~~~