Language: C++

#include <bits/stdc++.h>

typedef long long ll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair

using namespace std;

const int N = 1e6 + 69;
const ll INF = 1e18;

int n, m;
vector < pair < int, int > > intervals[N];

ll tree[N*4], toadd[N*4];

void upd(int node, int tl, int tr, int l, int r, int  val){
        if(tl > r || l > tr) return ;

        if(l <= tl && tr <= r){
                tree[node] += val;
                toadd[node] += val;
                return ;
        }

        int mid = ((tl + tr) >> 1);
        int left = (node << 1);
        int right = (left | 1);

        if(toadd[node]){
                for(int i = left; i <= right; i++){
                        toadd[i] += toadd[node];
                        tree[i] += toadd[node];
                }
                toadd[node] = 0;
        }

        upd(left, tl, mid, l, r, val);
        upd(right, mid+1, tr, l, r, val);

        tree[node] = min(tree[left], tree[right]);

}

ll get(int node, int tl, int tr, int l, int r){
        if(tl > r || l > tr) return INF;

        if(l <= tl && tr <= r) return tree[node];

        int mid = ((tl + tr) >> 1);
        int left = (node << 1);
        int right = (left | 1);

        if(toadd[node]){
                for(int i = left; i <= right; i++){
                        toadd[i] += toadd[node];
                        tree[i] += toadd[node];
                }
                toadd[node] = 0;
        }


        ll x = get(left, tl, mid, l, r);
        ll y = get(right, mid+1, tr, l, r);

        return min(x, y);
}

int main(){

        ios::sync_with_stdio(0);

        cin >> n >> m;
        ll sum = 0;
        for(int i = 1; i <= m; i++){
                int a, b, c;
                cin >> a >> b >> c;
                intervals[b].pb({a,c});
                sum += c;
        }

        for(int i = 1; i <= n; i++){
                if(i > 1){
                        ll x = get(1, 1, n, 1, i - 1);
                        upd(1, 1, n, i, i, x);
                }
                for(auto p : intervals[i]){
                        if(p.ff - 1) upd(1, 1, n, 1, p.ff - 1, p.ss);
                }
        }

        cout << max(sum - tree[1], 0) << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:95:20: error: no matching function for call to 'max(ll, int)'
   95 |         cout << max(sum - tree[1], 0) << endl;
      |                 ~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:95:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   95 |         cout << max(sum - tree[1], 0) << endl;
      |                 ~~~^~~~~~~~~~~~~~~~~~
/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
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:95:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   95 |         cout << max(sum - tree[1], 0) << endl;
      |                 ~~~^~~~~~~~~~~~~~~~~~