func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000000000000;   struct fun {     long long a, b, nr;   };   void Dodaj(deque<fun>& D, fun nowy) {     while (D.size() >= 2) {       fun ost = D.front();       D.pop_front();       fun przed = D.front();       if ((ost.b - nowy.b) * (ost.a - przed.a) >           (nowy.a - ost.a) * (przed.b - ost.b)) {         D.push_front(ost);         break;       }     }     D.push_front(nowy);   }   int Pytaj(deque<fun>& D, long long x) {     while (D.size() >= 2) {       fun ost = D.back();       D.pop_back();       fun przed = D.back();       if (ost.a * x + ost.b < przed.a * x + przed.b) {         D.push_back(ost);         break;       }     }     return D.back().nr;   }   int main() {     ios_base::sync_with_stdio(0);     int n, m, p;     cin >> n >> m >> p;     vector<long long> s(n);     s[0] = 0;     for (int i = 1; i < n; ++i) {       cin >> s[i];       s[i] += s[i - 1];     }     vector<long long> a(m);     for (int i = 0; i < m; ++i) {       int h, t;       cin >> h >> t;       --h;       a[i] = t - s[h];     }     sort(a.begin(), a.end());     vector<long long> prefA(m);     prefA[0] = a[0];     for (int i = 1; i < m; ++i) prefA[i] = prefA[i - 1] + a[i];     vector<vector<long long> > dp(p, vector<long long>(m, INF));     for (int i = 0; i < m; ++i) dp[0][i] = a[i] * (i + 1) - prefA[i];     for (int i = 1; i < p; ++i) {       deque<fun> D;       Dodaj(D, {-(i - 1), dp[i - 1][i - 1] + prefA[i - 1], i - 1});       for (int j = i; j < m; ++j) {         int nr = Pytaj(D, a[j]);         dp[i][j] = dp[i - 1][nr] + a[j] * (j - nr) - prefA[j] + prefA[nr];         Dodaj(D, {-j, dp[i - 1][j] + prefA[j], j});       }     }     long long odp = INF;     for (int i = 0; i < p; ++i) odp = min(odp, dp[i][m - 1]);     cout << odp;     return 0;   }   