样例过了,但是全WE。。
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int n, k, s;
set<int> stt;
int main()
{
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> k;
if (k == 1)
{
cin >> s;
auto iter = stt.find(s);
if (iter != stt.end())
cout << "Already Exist" << endl;
else
stt.insert(s);
}
else
{
if (stt.empty()==true)
{
cout << "Empty" << endl;
continue;
}
cin >> k;
auto iter1 = stt.lower_bound(k);
auto iter2 = iter1;
if (iter2 != stt.begin())
iter2--;
if (iter1 != stt.end() && (k - (*iter2) > (*iter1 - k)))
iter2 = iter1;
cout << *iter2 << endl;
stt.erase(iter2);
}
}
return 0;
}