Queue + Multiset | C++ | Simple Solution
\nclass MKAverage {\npublic:\n    \n    queue<int> q;\n    multiset<int> mk;\n    int total;\n    int kt;\n    MKAverage(int m, int k) {\n        total = m;\n  
```\nclass MKAverage {\npublic:\n    \n    queue<int> q;\n    multiset<int> mk;\n    int total;\n    int kt;\n    MKAverage(int m, int k) {\n        total = m;\n        kt = k;\n    }\n    \n    void addElement(int num) {\n        \n        if(q.size() == total){\n            int e = q.front();\n            q.pop();\n            auto it = mk.find(e);\n            mk.erase(it);            \n        }\n        \n        q.push(num);\n        mk.insert(num);        \n    }\n    \n    int calculateMKAverage() {\n        \n        if(q.size() < total)\n            return -1;\n        \n        long long sum = 0;\n        int counts = total - 2*kt;\n        int a = counts;\n        int t = 0;\n        auto it = mk.begin();\n        while(t < kt){\n            it++;\n            t++;                \n        }\n        \n        \n        while(counts){\n            sum += *it;\n            it++;\n            counts--;\n        }\n        \n        \n        return sum/a;\n    }\n};\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * MKAverage* obj = new MKAverage(m, k);\n * obj->addElement(num);\n * int param_2 = obj->calculateMKAverage();\n */\n ```
[]