- array-rearrange, Arrays, Heap, Mathematical

Maximize average of the ratios of N pairs by M increments

  #include using namespace std;  double change(int pass, int total){    double currentPassRatio, newPassRatio;    double increase;          currentPassRatio = ((double)pass)                       / total;          newPassRatio = ((double)(pass + 1))                   / (total + 1);          increase = newPassRatio               – currentPassRatio;          return increase;}  double maximumAverage(    vector v, int M,    int N){        double sum = 0;      double increase, average;              priority_queue pq;    for (int i = 0; i < N; i++) {                          increase = change(v[i][0], v[i][1]);                          pq.push({ increase, i });                  average = v[i][0] * 1.0 / v[i][1];                  sum += average;    }          while (M > 0) {                          sum += pq.top().first;          int i = pq.top().second;                          pq.pop();                                  v[i][0] += 1;        v[i][1] += 1;                          pq.push({ change(v[i][0], v[i][1]), i });                  M–;    }              double ans = sum / N;          return ans;}  int main(){    vector V        = { { 1, 2 }, { 3, 5 }, { 2, 2 } };    int M = 2;    int N = V.size();    cout