```
class Solution {
public:
vector<int> maxSlidingWindow(vector<int>& nums, int k) {
int i, n = nums.size();
vector<int> result;
multiset<int> mySet;
for(i=0; i<n; i++)
{
if(i>=k)
mySet.erase(mySet.find(nums[i-k]));
mySet.insert(nums[i]);
if(mySet.size()>=k)
result.push_back(*mySet.rbegin());
}
return result;
}
};
```