#include <bits/stdc++.h>   using namespace std;   long long dp[100050][205];   int redpac[100050][4];   int e[100050];   bool cmp(int x, int y) { return redpac[x][0] < redpac[y][0]; }   int main() {     int n, m, k, cur = 0;     long long ans = -1;     priority_queue<pair<int, pair<int, int> > > availablepackets;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < k; i++) {       scanf( %d%d%d%d , &redpac[i][0], &redpac[i][1], &redpac[i][2],             &redpac[i][3]);       e[i] = i;     }     sort(e, e + k, cmp);     memset(dp, -1, sizeof(dp));     dp[1][0] = 0;     for (int i = 1; i <= n; i++) {       if (availablepackets.size() > 0) {         while (availablepackets.top().second.second < i) {           availablepackets.pop();           if (availablepackets.size() == 0) break;         }       }       while (cur < k && redpac[e[cur]][0] <= i) {         availablepackets.push(make_pair(             redpac[e[cur]][3], make_pair(redpac[e[cur]][2], redpac[e[cur]][1])));         cur++;       }       for (int j = 0; j < m + 1; j++) {         if (dp[i][j] == -1) continue;         if (j < m && (dp[i + 1][j + 1] > dp[i][j] || dp[i + 1][j + 1] == -1)) {           dp[i + 1][j + 1] = dp[i][j];         }         if (availablepackets.size() > 0) {           if (dp[availablepackets.top().second.first + 1][j] >                   dp[i][j] + availablepackets.top().first ||               dp[availablepackets.top().second.first + 1][j] == -1) {             dp[availablepackets.top().second.first + 1][j] =                 dp[i][j] + availablepackets.top().first;           }         } else {           if (dp[i + 1][j] == -1 || dp[i + 1][j] > dp[i][j]) {             dp[i + 1][j] = dp[i][j];           }         }       }     }     for (int i = 0; i < m + 1; i++) {       if (dp[n + 1][i] != -1 && (ans > dp[n + 1][i] || ans == -1)) {         ans = dp[n + 1][i];       }     }     printf( %lld , ans);   }   