#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8Y21hdGg+CgpjbGFzcyBUZXN0IHsKcHVibGljOgogICAgVGVzdChpbnQgcmVmZXJlbmNlKSA6IAogICAgICAgIG1fcmVmZXJlbmNlKCByZWZlcmVuY2UgKSwKICAgICAgICBtX3ByaW9yaXR5KCAKICAgIAkgICAgW3JlZj1yZWZlcmVuY2VdKCBpbnQgYSwgaW50IGIgKSB7CiAgICAJICAgICAgICByZXR1cm4gc3RkOjphYnMoIGEgLSByZWYgKSA8IHN0ZDo6YWJzKCBiIC0gcmVmICk7IAogICAgICAgICAgICB9ICkKICAgIHsgIH0KICAgIHZvaWQgZmVlZChpbnQgeCkgeyBtX3ByaW9yaXR5LnB1c2goeCk7IH0KICAgIGludCBnZXQoKSB7IHJldHVybiBtX3ByaW9yaXR5LnRvcCgpOyB9CnByaXZhdGU6CiAgICBpbnQgbV9yZWZlcmVuY2U7CiAgICBzdGQ6OnByaW9yaXR5X3F1ZXVlPGludCwgc3RkOjp2ZWN0b3I8aW50Piwgc3RkOjpmdW5jdGlvbjxib29sKGludCxpbnQpPj4gbV9wcmlvcml0eTsKfTsKCmludCBtYWluKCkgewogIFRlc3QgdGVzdCgxMyk7CiAgdGVzdC5mZWVkKDEpOwogIHRlc3QuZmVlZCgxMCk7CiAgdGVzdC5mZWVkKDIwKTsKCiAgYXV0byB4ID0gdGVzdC5nZXQoKTsKCiAgc3RkOjpjb3V0IDw8IHggPDwgc3RkOjplbmRsOwp9