func_code_string: #include <bits/stdc++.h>   using namespace std;   struct Edge {     int v, next;   } edge[2050];   int e, ft[2050];   int a, n, m;   bool rain[2050];   int x[2050], p[2050];   long long dp[2050][2050];   long long opt[2050];   int main() {     int l, r;     while (cin >> a >> n >> m) {       e = 0;       for (int i = 0; i <= a; i++) {         rain[i] = false;         for (int j = 0; j <= m; j++) dp[i][j] = (1ll << 60);         ft[i] = -1;       }       for (int i = 0; i < n; i++) {         scanf( %d%d , &l, &r);         while (l < r) {           rain[l++] = true;         }       }       for (int i = 0; i < m; i++) {         scanf( %d%d , x + i, p + i);         edge[e].v = i;         edge[e].next = ft[x[i]];         ft[x[i]] = e++;         if (x[i] == 0) dp[0][i] = 0;       }       dp[0][m] = 0;       p[m] = 0;       opt[0] = 0;       for (int i = 0; i < a; i++) {         for (int j = 0; j <= m; j++) {           if (dp[i][j] >= (1ll << 60)) continue;           if (j < m || !rain[i])             dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + p[j]);         }         opt[i + 1] = (1ll << 60);         for (int j = 0; j <= m; j++) opt[i + 1] = min(opt[i + 1], dp[i + 1][j]);         for (int j = ft[i + 1]; j != -1; j = edge[j].next) {           int idx = edge[j].v;           dp[i + 1][idx] = min(dp[i + 1][idx], opt[i + 1]);         }         dp[i + 1][m] = min(dp[i + 1][m], opt[i + 1]);       }       long long ans = -1;       if (opt[a] < (1ll << 60)) ans = opt[a];       cout << ans << endl;     }     return 0;   }   