Audit Sale
Difficulty: Hard

After carefully auditing your portfolio, you notice you have $N$ securities left over from previous trades. You have only one unit of each of these $N$ securities, and you want to sell *at most* $M$ of these to avoid extra accounting.

As an experienced portfolio manager, you rely on your previous body of work to predict the price at which you can sell each lone security. For each of the $N$ securities, you write down two pieces of information: 

1. The price, $P$, at which you want to sell that security.
2. The probability (or confidence), $C$, that you can sell the security at that price.

Thus, the $i^{th}$ security has two values associated with it: the price, $P_i$, and the confidence, $C_i$. Drawing on your experience, you know with $100\%$ certainty that you can sell at least $K$ of the $N$ securities.

Given the information discussed above, find the maximum amount of money [expected](http://mathworld.wolfram.com/ExpectationValue.html) from $M$ sales, multiply it by $100$, and print the result. The first $K$ sales of your choice are guaranteed to be successful. 

Input Format:
The first line contains three space-separated integers: $N$ (the number of lone securities you have), $M$ (the maximum number of securities you wish to sell), and $K$ (the minimum number of securities you can definitely sell), respectively.	
Each line $i$ of the $N$ subsequent lines contains two space-separated integers describing the respective $P_i$ and $C_i$ values for security $i$ (where $0 \le i \lt N$).

Output Format:
Print a single integer denoting the maximum amount of money expected from $M$ sales, multiplied by $100$.

Sample Input:
    3 2 1
    5 10
    6 60
    8 40

Sample Output:
1160

Python 3 starter code:


Reference solution (C++):
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    const int N = 100010;
    int n, m, k;
    vector<pair<int, pair<int, int> > > v;
    int hSum[N], hpSum[N]; 
    //hSum[i] stores sum of mamimum K pricw values till i
    //hpSum[i] stores sum of maximum (M - K) price * probability values with index >= i

    #undef int
    int main()
    {
      #define int long long
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cin >> n >> m >> k;
      for(int i=0; i<n; i++)  {
        int hi, pi; cin >> hi >> pi;
        v.push_back({hi * (100 - pi), {hi, pi}});
      }
      sort(v.begin(), v.end());
      reverse(v.begin(), v.end());
      multiset<int> s;
      long long curSum = 0;
      for(int i=0; i<n; i++)  {
        int curH = v[i].second.first;
        if(i < k) {
          s.insert(curH);
          curSum += curH;
        } else if(s.size()) {
          int mn = *(s.begin());
          if(mn < curH) {
            s.erase(s.begin());
            curSum -= mn;
            curSum += curH;
            s.insert(curH);
          }
        }
        hSum[i] = curSum;
      }
      s.clear();
      curSum = 0;
      for(int i=n-1; i>=0; i--) {
        int curHp = v[i].second.first * v[i].second.second;
        if(n - i - 1 < m - k) {
          s.insert(curHp);
          curSum += curHp;
        } else if(s.size()) {
          int mn = *(s.begin());
          if(mn < curHp)  {
            s.erase(s.begin());
            curSum -= mn;
            curSum += curHp;
            s.insert(curHp);
          }
        }
        hpSum[i] = curSum;
      } 
      hpSum[n] = 0;
      long long ans = -1;
      for(int i=0; i<n; i++)  {
        ans = max(ans, hSum[i]*100 + hpSum[i+1]);
      }
      ans = max(ans, hpSum[0]);
      cout << ans << "\n";
    }