func_code_string: #include <bits/stdc++.h>   using namespace std;   inline void Boost() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const int NMax = 1e5 + 50;   struct Event {     int d, w, t;     bool operator<(const Event &e) const {       if (w != e.w) return w > e.w;       return d > e.d;     }   };   vector<int> DP, jump;   map<Event, int> Map;   vector<Event> v[NMax];   int main() {     Boost();     int n, k, m;     cin >> n >> m >> k;     DP.resize(n);     jump.resize(n);     for (int i = 0; i < n; ++i) jump[i] = i + 1;     for (int i = 0; i < k; ++i) {       int s, t, d, w;       cin >> s >> t >> d >> w;       v[s - 1].push_back({d, w, 1});       v[t].push_back({d, w, 0});     }     for (int i = 0; i < n; ++i) {       for (auto x : v[i]) {         if (x.t == 1) {           if (Map.count(x)) {             ++Map[x];           } else {             Map[x] = 1;           }         } else {           --Map[x];           if (Map[x] == 0) {             Map.erase(x);           }         }       }       if (!Map.empty()) {         DP[i] = (*Map.begin()).first.w;         jump[i] = (*Map.begin()).first.d;       }     }     vector<long long int> ans[m + 1];     for (auto &x : ans) x.resize(n + 1, LLONG_MAX);     ans[0][0] = 0;     for (int i = 0; i <= n; ++i) {       for (int j = 1; j <= m && i; ++j) {         ans[j][i] = min(ans[j][i], ans[j - 1][i - 1]);       }       for (int j = 0; j <= m && i < n; ++j) {         if (ans[j][i] == LLONG_MAX) continue;         ans[j][jump[i]] = min(ans[j][jump[i]], ans[j][i] + DP[i]);       }     }     long long int ret = ans[0][n];     for (int i = 0; i <= m; ++i) {       ret = min(ret, ans[i][n]);     }     cout << ret;     return 0;   }   