Language: C++

#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;
a#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 2e5 + 5;

class SegmentTree {
public:
	int N;
	vector<ll> minimum, delta;

	SegmentTree() {}

	SegmentTree(int N) {
		this->N = N;
		minimum = vector<ll>(4 * N + 1);
		delta = vector<ll>(4 * N + 1);
	}
	
	void update(int l, int r, ll val) {update(1, 0, N - 1, l, r, val);} //inclusive range
	
	ll query(int l, int r) {return query(1, 0, N - 1, l, r);} //inclusive range
	
	void push(int i) {
		delta[2 * i] += delta[i];
		delta[2 * i + 1] += delta[i];
		delta[i] = 0;
	}

	void pull(int i) {
		minimum[i] = min(minimum[2 * i] + delta[2 * i], minimum[2 * i + 1] + delta[2 * i + 1]);
	}
	
	void update(int i, int lo, int hi, int l, int r, ll val) {
		if (r < lo || hi < l) return;
		if (l <= lo && hi <= r) {
			delta[i] += val;
			return;
		}
		
		push(i);
		
		int m = (lo + hi) / 2;
		update(2 * i, lo, m, l, r, val);
		update(2 * i + 1, m + 1, hi, l, r, val);
		
		pull(i);
	}
	
	ll query(int i, int lo, int hi, int l, int r) {
		if (r < lo || hi < l) return (1 << 29);
		if (l <= lo && hi <= r) {
			return minimum[i] + delta[i];
		}
		
		push(i);
		
		int m = (lo + hi) / 2;
		ll minLeft = query(2 * i, lo, m, l, r);
		ll minRight = query(2 * i + 1, m + 1, hi, l, r);
		
		pull(i);
		
		return min(minLeft, minRight);
	}
};

int N, M;
vector<pi> intervals[MAX_N];
SegmentTree st(MAX_N);

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> M;
	ll sum = 0;
	for (int i = 0; i < M; ++i) {
		int l, r, a; cin >> l >> r >> a;
		intervals[r].push_back({l, a});
		sum += a;
	}

	for (int i = 1; i <= N + 1; ++i) {
		for (pi seg: intervals[i - 1]) {
			st.update(0, seg.ff - 1, seg.ss);
		}
		st.update(i, i, st.query(0, i - 1));
	}

	cout << sum - st.query(0, N + 1) << '\n';

	return 0;
}
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 2e5 + 5;

class SegmentTree {
public:
	int N;
	vector<ll> minimum, delta;

	SegmentTree() {}

	SegmentTree(int N) {
		this->N = N;
		minimum = vector<ll>(4 * N + 1);
		delta = vector<ll>(4 * N + 1);
	}
	
	void update(int l, int r, ll val) {update(1, 0, N - 1, l, r, val);} //inclusive range
	
	ll query(int l, int r) {return query(1, 0, N - 1, l, r);} //inclusive range
	
	void push(int i) {
		delta[2 * i] += delta[i];
		delta[2 * i + 1] += delta[i];
		delta[i] = 0;
	}

	void pull(int i) {
		minimum[i] = min(minimum[2 * i] + delta[2 * i], minimum[2 * i + 1] + delta[2 * i + 1]);
	}
	
	void update(int i, int lo, int hi, int l, int r, ll val) {
		if (r < lo || hi < l) return;
		if (l <= lo && hi <= r) {
			delta[i] = min(delta[i], val);
			return;
		}
		
		push(i);
		
		int m = (lo + hi) / 2;
		update(2 * i, lo, m, l, r, val);
		update(2 * i + 1, m + 1, hi, l, r, val);
		
		pull(i);
	}
	
	ll query(int i, int lo, int hi, int l, int r) {
		if (r < lo || hi < l) return (1 << 29);
		if (l <= lo && hi <= r) {
			return minimum[i] + delta[i];
		}
		
		push(i);
		
		int m = (lo + hi) / 2;
		ll minLeft = query(2 * i, lo, m, l, r);
		ll minRight = query(2 * i + 1, m + 1, hi, l, r);
		
		pull(i);
		
		return min(minLeft, minRight);
	}
};

int N, M;
vector<pi> intervals[MAX_N];
SegmentTree st(MAX_N);

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> M;
	ll sum = 0;
	for (int i = 0; i < M; ++i) {
		int l, r, a; cin >> l >> r >> a;
		intervals[r].push_back({l, a});
		sum += a;
	}

	for (int i = 1; i <= N + 1; ++i) {
		st.update(i, i, st.query(0, i - 1));
		for (pi seg: intervals[i - 1]) {
			st.update(i, i, st.query(0, seg.ff - 1) + seg.ss);
		}
	}

	cout << sum - st.query(0, N + 1) << '\n';

	return 0;
}

Compiler output:
a.cc:12:2: error: stray '#' in program
   12 | a#include <bits/stdc++.h>
      |  ^
a.cc:12:1: error: 'a' does not name a type
   12 | a#include <bits/stdc++.h>
      | ^
a.cc:116:11: error: redefinition of 'const int MOD'
  116 | const int MOD = 1e9 + 7;
      |           ^~~
a.cc:24:11: note: 'const int MOD' previously defined here
   24 | const int MOD = 1e9 + 7;
      |           ^~~
a.cc:117:10: error: redefinition of 'const ll INF'
  117 | const ll INF = 1e18;
      |          ^~~
a.cc:25:10: note: 'const ll INF' previously defined here
   25 | const ll INF = 1e18;
      |          ^~~
a.cc:118:14: error: redefinition of 'const double EPS'
  118 | const double EPS = 1e-6;
      |              ^~~
a.cc:26:14: note: 'const double EPS' previously defined here
   26 | const double EPS = 1e-6;
      |              ^~~
a.cc:119:11: error: redefinition of 'const int MAX_N'
  119 | const int MAX_N = 2e5 + 5;
      |           ^~~~~
a.cc:27:11: note: 'const int MAX_N' previously defined here
   27 | const int MAX_N = 2e5 + 5;
      |           ^~~~~
a.cc:121:7: error: redefinition of 'class SegmentTree'
  121 | class SegmentTree {
      |       ^~~~~~~~~~~
a.cc:29:7: note: previous definition of 'class SegmentTree'
   29 | class SegmentTree {
      |       ^~~~~~~~~~~
a.cc:182:5: error: redefinition of 'int N'
  182 | int N, M;
      |     ^
a.cc:90:5: note: 'int N' previously declared here
   90 | int N, M;
      |     ^
a.cc:182:8: error: redefinition of 'int M'
  182 | int N, M;
      |        ^
a.cc:90:8: note: 'int M' previously declared here
   90 | int N, M;
      |        ^
a.cc:183:12: error: redefinition of 'std::vector<std::pair<int, int> > intervals [200005]'
  183 | vector<pi> intervals[MAX_N];
      |            ^~~~~~~~~
a.cc:91:12: note: 'std::vector<std::pair<int, int> > intervals [200005]' previously declared here
   91 | vector<pi> intervals[MAX_N];
      |            ^~~~~~~~~
a.cc:184:13: error: redefinition of 'SegmentTree st'
  184 | SegmentTree st(MAX_N);
      |             ^~
a.cc:92:13: note: 'SegmentTree st' previously declared here
   92 | SegmentTree st(MAX_N);
      |             ^~
a.cc:186:5: error: redefinition of 'int main()'
  186 | int main() {
      |     ^~~~
a.cc:94:5: note: 'int main()' previously defined here
   94 | int main() {
      |     ^~~~