#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <cmath>

class Test {
public:
    Test(int reference) : 
        m_reference( reference ),
        m_priority( 
    	    [ref=reference]( int a, int b ) {
    	        return std::abs( a - ref ) < std::abs( b - ref ); 
            } )
    {  }
    void feed(int x) { m_priority.push(x); }
    int get() { return m_priority.top(); }
private:
    int m_reference;
    std::priority_queue<int, std::vector<int>, std::function<bool(int,int)>> m_priority;
};

int main() {
  Test test(13);
  test.feed(1);
  test.feed(10);
  test.feed(20);

  auto x = test.get();

  std::cout << x << std::endl;
}