#include <iostream>#include <algorithm>#include <vector>using namespace std;vector<pair<int, int>> list[2021];int N, C, M, capacity[2021];int min(int a, int b) { return a < b ? a : b;}int main() { cin >> N >> C >> M; for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; list[b].push_back({ a,c }); } for (int i = 1; i <= N; i++) { capacity[i] = C; sort(list[i].begin(), list[i].end()); } int shipped = 0; for (int i = 2; i <= N; i++) { for (int j = list[i].size() - 1; j >= 0; j--) { int s = list[i][j].first, box = list[i][j].second, m = 2000000000; for (int k = s; k < i; k++) { m = min(m, capacity[k]); } int howMany = min(box, m); for (int k = s; k < i; k++) capacity[k] -= howMany; shipped += howMany; } } cout<< shipped;}