Language: C++

#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

using namespace std;
using ll = long long;
using getTwoNodeValueFunc = ll (*)(ll a, ll b);
using updateOneNodeValueFunc = ll (*)(ll a, ll b);

const ll NEG_INF = -1e12;
const int NMAX = 2e5 + 5;

ll getMax(ll a, ll b) {
    return max(a, b);
}

ll updateAdd(ll a, ll b) {
    return  a+b;
}

class LazySegmentTree {
private:
    int numItems;
    vector<ll> tree;
    vector<ll> lazy;
    getTwoNodeValueFunc getFunc;
    updateOneNodeValueFunc updateFunc;
    int getNumberOfNodes() {
        int x = int(ceil(log2(numItems)));
        return ((1-pow(2, x+1))/(1-2)) + 1;
    };
    void buildTree() {
        vector<ll> t1(getNumberOfNodes(), 0);
        tree = t1;
        vector<ll> t2(getNumberOfNodes(), 0);
        lazy = t2;
    };
    void _update(ll value, int ind, int start, int end, int l, int r) {
        // update value of 1 node in tree
        // [start, end] is an updating index interval of segment tree
        // [l, r] is user input index interval
        if (lazy[ind] != 0) {
            tree[ind] = updateFunc(tree[ind], lazy[ind]);
            if (start != end) {
                lazy[2*ind+1] = updateFunc(lazy[2*ind+1], lazy[ind]);
                lazy[2*ind+2] = updateFunc(lazy[2*ind+2], lazy[ind]);
            }    
            lazy[ind] = 0;
        }
            
        if (start > r || end < l) return;
        if (start >= l && end <= r) {
            tree[ind] = updateFunc(tree[ind], value);
            if (start != end) {
                lazy[2*ind+1] = updateFunc(lazy[2*ind+1], value);
                lazy[2*ind+2] = updateFunc(lazy[2*ind+2], value);
            }
            return;
        }
            
        int mid = (start+end)/2;
        _update(value, 2*ind+1, start, mid, l, r);
        _update(value, 2*ind+2, mid+1, end, l, r);
        tree[ind] = getFunc(tree[2*ind+1], tree[2*ind+2]);
    };
    ll _query(int ind, int start, int end, int l, int r) {
        if (lazy[ind] != 0) {
            tree[ind] = updateFunc(tree[ind], lazy[ind]);
            if (start != end) {
                lazy[2*ind+1] = updateFunc(lazy[2*ind+1], lazy[ind]);
                lazy[2*ind+2] = updateFunc(lazy[2*ind+2], lazy[ind]);
            }
            lazy[ind] = 0;
        }
            
        if (start > r || end < l) return NEG_INF;

        if (start >= l && end <= r) return tree[ind];

        int mid = (start + end)/2;
        ll a = _query(2*ind+1, start, mid, l, r);
        ll b = _query(2*ind+2, mid+1, end, l, r);
        if (a == NEG_INF) return b;
        else if (b == NEG_INF) return a;
        return getFunc(a, b);
    };
public:
    LazySegmentTree(int numItemsx, getTwoNodeValueFunc get, updateOneNodeValueFunc update) {
        numItems = numItemsx;
        getFunc = get;
        updateFunc = update;
        buildTree();
    };
    void update(ll value, int l, int r) {
        return _update(value, 0, 0, numItems-1, l, r);
    };
    ll query(int l, int r) {
        return _query(0, 0, numItems-1, l, r);
    };
};

struct P {
    int l;
    int r;
    ll val;
};
vector<P> v;
ll dp[NMAX] = {NEG_INF};

ll solve(int n, int m) {
    for (int i = 0; i <= n; i++) dp[i] = NEG_INF;
    ll t = 0;
    for (int i = 0; i < m; i++) {
        if (v[i].l <= 1 && v[i].r >= 1) {
            t += v[i].val;
        }
    }
    dp[1] = t;
    // printf("%d %lld\n", 1, dp[1]);
    ll rs = dp[1];
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j < i; j++) {
            ll t = 0;
            for (int k = 0; k < m; k++) {
                if (v[k].l <= i && v[k].r >= i && (v[k].l > j || v[k].r < j)) {
                    t += v[k].val;
                }
            }
            dp[i] = max(dp[i], dp[j]+t);
        }
        // printf("%d %lld\n", i, dp[i]);
        rs = max(dp[i], rs);
    }
    return max(0, rs);
}

int main() {
    int n, m, l, r;
    ll val;
    cin >> n >> m;
    // LazySegmentTree tree(n+5, (getTwoNodeValueFunc)getMax, (updateOneNodeValueFunc)updateAdd);
    // for (int i = 0; i < m; i++) {
    //     cin >> l >> r >> val;
    //     tree.update(val, l, r);
    // }
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> val;
        v.push_back({l,r,val});
    }
    // printf("-----------\n");
    printf("%lld\n", solve(n,m));
    return 0;
}


Compiler output:
a.cc: In function 'll solve(int, int)':
a.cc:135:15: error: no matching function for call to 'max(int, ll&)'
  135 |     return max(0, rs);
      |            ~~~^~~~~~~
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: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:135:15: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  135 |     return max(0, rs);
      |            ~~~^~~~~~~
/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