This is not a homework.
I\'m using a small \"priority queue\" (implemented as array at the moment) for storing last N items with smallest value. This is a b
Use std::priority_queue
with the largest item at the head. For each new item, discard it if it is >=
the head item, otherwise pop the head item and insert the new item.
Side note: Standard containers will only grow if you make them grow. As long as you remove one item before inserting a new item (after it reaches its maximum size, of course), this won't happen.