Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
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"){
				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:16:12: error: reference to 'data' is ambiguous
   16 |         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:9:12: note:                 'std::vector<std::pair<int, int> > data'
    9 | vector<pr> data;
      |            ^~~~
a.cc: In function 'bool can(int, int)':
a.cc:25:34: error: reference to 'data' is ambiguous
   25 |         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:9:12: note:                 'std::vector<std::pair<int, int> > data'
    9 | vector<pr> data;
      |            ^~~~
a.cc:28:24: error: reference to 'data' is ambiguous
   28 |         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:9:12: note:                 'std::vector<std::pair<int, int> > data'
    9 | vector<pr> data;
      |            ^~~~
a.cc: In function 'int search(int)':
a.cc:35:19: error: 'pow' was not declared in this scope
   35 |         int f=0,s=pow(10,9);
      |                   ^~~
a.cc: In function 'int main()':
a.cc:54:25: error: reference to 'data' is ambiguous
   54 |                         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:9:12: note:                 'std::vector<std::pair<int, int> > data'
    9 | vector<pr> data;
      |            ^~~~
a.cc:56:22: error: reference to 'data' is ambiguous
   56 |                 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:9:12: note:                 'std::vector<std::pair<int, int> > data'
    9 | vector<pr> data;
      |            ^~~~
a.cc:56:35: error: reference to 'data' is ambiguous
   56 |                 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:9:12: note:                 'std::vector<std::pair<int, int> > data'
    9 | vector<pr> data;
      |            ^~~~
a.cc:58:54: error: expected primary-expression before '(' token
   58 |                         point.insert(mapi::value_type(data[i].second,i));
      |                                                      ^
a.cc:58:55: error: reference to 'data' is ambiguous
   58 |                         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:9:12: note:                 'std::vector<std::pair<int, int> > data'
    9 | vector<pr> data;
      |            ^~~~
a.cc:82:17: error: reference to 'data' is ambiguous
   82 |                 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:                 '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> co