c++ solution
\nclass MKAverage\n{\n    public:\n        multiset<int> left, mid, right;\n    int k;\n    int m;\n    long long sum;\n    queue<int> q;\n    MKAverage(int mt,
```\nclass MKAverage\n{\n    public:\n        multiset<int> left, mid, right;\n    int k;\n    int m;\n    long long sum;\n    queue<int> q;\n    MKAverage(int mt, int kt)\n    {\n        sum = 0;\n        m = mt;\n        k = kt;\n    }\n    void remove()\n    {\n        int val = q.front();\n        q.pop();\n        if (val <= *left.rbegin())\n        {\n            left.erase(left.find(val));\n            left.insert(*mid.begin());\n            sum -= *mid.begin();\n            mid.erase(mid.begin());\n        }\n        else if (val >= *right.begin())\n        {\n            right.erase(right.find(val));\n            right.insert(*mid.rbegin());\n            sum -= *mid.rbegin();\n            mid.erase(--mid.end());\n        }\n        else\n        {\n            sum -= val;\n            mid.erase(mid.find(val));\n        }\n    }\n    void add(int val)\n    {\n        q.push(val);\n        if (mid.size() == 0)\n        {\n            if (q.size() == m)\n            {\n                queue<int> nq = q;\n                vector<int> v;\n                while (nq.size())\n                {\n                    v.push_back(nq.front());\n                    nq.pop();\n                }\n                sort(v.begin(), v.end());\n                for (int i = 0; i < m; i++)\n                {\n                    if (i < k)\n                    {\n                        left.insert(v[i]);\n                    }\n                    else if (i > m - 1 - k)\n                    {\n                        right.insert(v[i]);\n                    }\n                    else\n                    {\n                        mid.insert(v[i]);\n                        sum += v[i];\n                    }\n                }\n            }\n        }\n        else if (val<*left.rbegin())\n        {\n            int curr = *left.rbegin();\n            left.insert(val);\n            mid.insert(curr);\n            left.erase(--left.end());\n            sum += curr;\n        }\n        else if (val > *right.begin())\n        {\n            int curr = *right.begin();\n            right.erase(right.begin());\n            right.insert(val);\n            sum += curr;\n            mid.insert(curr);\n        }\n        else\n        {\n            sum += val;\n            mid.insert(val);\n        }\n    }\n    void addElement(int num)\n    {\n        add(num);\n        if (q.size() > m)\n        {\n            remove();\n        }\n    }\n\n    int calculateMKAverage()\n    {\n        if (q.size() < m)\n        {\n            return -1;\n        }\n        return sum / mid.size();\n    }\n};\n```
['C', 'C++']