Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
typedef map<int,int> mapi;
typedef pair<int,int> pr;
vector<pr> data;
vector<int> leader;
int n,q;
int study(int lo,int hi,int needs){
	int f=lo,s=hi;
	while(f<=s){
	int mid=(f+s)/2;
	if(data[mid].first>=needs)
		s=mid-1;
	else
		f=mid+1;
	}
	return s-lo+1;
}
bool can(int space,int score){
	int sum=0;
	sum+=study(0,leader[0]-1,data[leader[0]].first-score);
	for(int i=1;i<leader.size();i++){
	int f=leader[i-1]+1,s=leader[i]-1;
	sum+=study(f,s,data[leader[i]].first-score);
	}
	sum+=n-(leader[leader.size()-1]+1);
	return space>=sum;

}
int search(int space){
	int f=0,s=pow(10,9);
	while(f<=s){
	int mid=(f+s)/2;
	if(can(space,mid))
		s=mid-1;
	else
		f=mid+1;
	}
	return f;
}
int main() {
	// your code goes here
	int tmp;
	string tmps;
	while(cin >>n >> q && n!=0){
	mapi point;
		for(int i=0;i<n;i++){
			cin >> tmp;
			//point.insert(mapi::value_type(i+1,tmp));
			data.push_back(pr(tmp,i+1));
		}
		sort(data.begin(),data.end());
		for(int i=0;i<n;i++)
			point.insert(mapi::value_type(data[i].second,i));

		for(int j=0;j<q;j++){
			cin >> tmps >> tmp;
			if(tmps=="ADD")
				leader.push_back(point[tmp]);
			if(tmps=="REMOVE"){
				for(vector<int>::iterator it=leader.begin()++;it!=leader.end();++it)
					if(*it==point[tmp]){
						it=leader.erase(it);
						break;
					}
			}
			if(tmps=="CHECK"){
				if(leader.size()==0)
				ans=1000000001;
				else
				int ans=search(tmp);
				if(ans==1000000001)
				cout << "NA" << endl;
				else
				cout << ans << endl;
			}
			else
			sort(leader.begin(),leader.end());
		}
		
		data.clear();
		leader.clear();
	}
	return 0;
}

Compiler output:
a.cc: In function 'int study(int, int, int)':
a.cc:17:12: error: reference to 'data' is ambiguous
   17 |         if(data[mid].first>=needs)
      |            ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:12: note:                 'std::vector<std::pair<int, int> > data'
   10 | vector<pr> data;
      |            ^~~~
a.cc: In function 'bool can(int, int)':
a.cc:26:34: error: reference to 'data' is ambiguous
   26 |         sum+=study(0,leader[0]-1,data[leader[0]].first-score);
      |                                  ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:12: note:                 'std::vector<std::pair<int, int> > data'
   10 | vector<pr> data;
      |            ^~~~
a.cc:29:24: error: reference to 'data' is ambiguous
   29 |         sum+=study(f,s,data[leader[i]].first-score);
      |                        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:12: note:                 'std::vector<std::pair<int, int> > data'
   10 | vector<pr> data;
      |            ^~~~
a.cc: In function 'int main()':
a.cc:55:25: error: reference to 'data' is ambiguous
   55 |                         data.push_back(pr(tmp,i+1));
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:12: note:                 'std::vector<std::pair<int, int> > data'
   10 | vector<pr> data;
      |            ^~~~
a.cc:57:22: error: reference to 'data' is ambiguous
   57 |                 sort(data.begin(),data.end());
      |                      ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:12: note:                 'std::vector<std::pair<int, int> > data'
   10 | vector<pr> data;
      |            ^~~~
a.cc:57:35: error: reference to 'data' is ambiguous
   57 |                 sort(data.begin(),data.end());
      |                                   ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:12: note:                 'std::vector<std::pair<int, int> > data'
   10 | vector<pr> data;
      |            ^~~~
a.cc:59:54: error: expected primary-expression before '(' token
   59 |                         point.insert(mapi::value_type(data[i].second,i));
      |                                                      ^
a.cc:59:55: error: reference to 'data' is ambiguous
   59 |                         point.insert(mapi::value_type(data[i].second,i));
      |                                                       ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:12: note:                 'std::vector<std::pair<int, int> > data'
   10 | vector<pr> data;
      |            ^~~~
a.cc:74:33: error: 'ans' was not declared in this scope; did you mean 'abs'?
   74 |                                 ans=1000000001;
      |                                 ^~~
      |                                 abs
a.cc:77:36: error: 'ans' was not declared in this scope; did you mean 'abs'?
   77 |                                 if(ans==1000000001)
      |                                    ^~~
      |                                    abs
a.cc:86:17: error: reference to 'data' is ambiguous
   86 |                 data.clear();
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: