# Queries to calculate average of an array after removing K smallest and largest elements with updates

#include using namespace std; class SpecialAverage {public: multiset left, mid, right; int n, k; long pos, sum; vector v; SpecialAverage(int nvalue, int kvalue) { n = nvalue; k = kvalue; pos = 0; sum = 0; for (int i = 0; i < n; i++) v.push_back(0); } void add(int num) { left.insert(num); if (left.size() > k) { int temp = *(prev(end(left))); mid.insert(temp); left.erase(prev(end(left))); sum += temp; } if (mid.size() > (n – 2 * k)) { int temp = *(prev(end(mid))); right.insert(temp); mid.erase(prev(end(mid))); sum -= temp; } } void remove(int ele) { if (ele = n) return ((double)sum) / (n – 2 * k); return -1; }}; void processQueries(int n, int k){ SpecialAverage* avg = new SpecialAverage(n, k); avg->addInteger(4); avg->addInteger(2); cout calculateSpecialAverage() addInteger(10); cout calculateSpecialAverage()