Language: C++

/* -----------------------------------------------------------------------------
	????????????????????? 2013 ?????? ??????8
	0283: Study Session
	???????????????(??£??????)
	g++ pckpre1308.cpp -O2
----------------------------------------------------------------------------- */
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

#define STUDENT_MAX (1000002)
#define SCORE_MAX	1000000002
#define INFTY		1000000002
//#define DEBUG

int score[STUDENT_MAX];		// ???????????????
map<int, int> MP;			// (??????, ?????°)
vector<int> ATI;			// ??????
vector<int> ATV;			// ?´?????????°

vector<int> leaders;		// ??????????????????????????????
vector<std::pair<int, int> > seg;	// ??????

int N;						// ????????°
int Q;						// ?????¨????????°
/*
/* -----------------------------------------------------------------------------
	???????????°??¨
----------------------------------------------------------------------------- */
void print_leaders() {

	int lcnt = leaders.size();

	printf("LEADERS: ");	
	for(int i = 0; i < lcnt; i++)
		printf("%d ", leaders[i]);
	printf("\n");

	return ;
}

void print_acc_score() {

	printf("ACC SCORE: ");
	for(int i = 0; i < ATI.size(); i++) {
		printf("%d %d\n", ATI[i], ATV[i]);
	}
	return ;
}
*/
/* -----------------------------------------------------------------------------
	????????¢??°
----------------------------------------------------------------------------- */
int add(int a) {

	// ?????????????????????a????????\???????????¢???
	leaders.push_back(score[a]);
	// ????????????????????????
	std::sort(leaders.begin(), leaders.end());

	return 0;
}


/* -----------------------------------------------------------------------------
	????????¢??°
----------------------------------------------------------------------------- */
int del(int a) {

	// ?????????????????????s????±??????????
	int s = score[a];
	// ??¢???
	vector<int>::iterator it = std::find(leaders.begin(), leaders.end(), s);
	// ?¶????
	if(it != leaders.end()) leaders.erase(it);

	return 0;
}


/* -----------------------------------------------------------------------------
	??????????????????r??\????????\??????????????°??????????????¢??°
----------------------------------------------------------------------------- */
int getCount(int r){

	seg.clear();

	if (leaders.size() > 0 ) seg.push_back(make_pair(leaders[0]-r, leaders[0]));

	for ( int i = 1; i < leaders.size(); i++ ){
		int b = leaders[i]-r;
		int e = leaders[i];
		if ( b <= seg[seg.size()-1].second){
			seg[seg.size()-1].second = max(seg[seg.size()-1].second, e);
		} else {
			seg.push_back(make_pair(b, e));
		}
	}

	int cnt = 0;
	for (int i = 0; i < seg.size(); i++) {
		int a = lower_bound(ATI.begin(), ATI.end(), max(0, seg[i].first)) - ATI.begin() - 1;
		int b = lower_bound(ATI.begin(), ATI.end(), max(0, seg[i].second)) - ATI.begin();
		cnt += ATV[b] - ATV[a];
	}
	return cnt;
}

/* -----------------------------------------------------------------------------
	??????????????????r??\???????????°
----------------------------------------------------------------------------- */
void bsearch(int X){

	int l = -1;
	int r = SCORE_MAX;
	int m;

	int cnt = getCount(r);
	if (cnt < X ) { cout << "NA" << endl; return;}
	while(1){
		m = (l+r)/2;
		cnt = getCount(m);
		if ( cnt >= X ){
			r = m;
		} else if ( cnt < X ){
			l = m;
		}
		if (r - l == 1) break;
	}
	cout << r << endl;
}


/* -----------------------------------------------------------------------------
	?????????????????°??????
----------------------------------------------------------------------------- */
int main() {

	char query[10];		// ??????
	int param;

	// ????????°N??¨?????¨????????°????????????
	scanf("%d %d", &N, &Q);

	// ????????¢????????????
	for(int i = 1; i <= N; i++) {
		int s;
		// i??????????????????????????¢???????????????
		scanf("%d", &s);
		// ????????¢????????°
		score[i] = s; 

		map<int, int>::iterator it = MP.find(s);
		if(it == MP.end())
			MP.insert(make_pair(s,1));
		else
			(*it).second ++;
	}

	// ?´???????
	ATI.push_back(-1);
	ATV.push_back(0);
	int pre = 0;
	for(map<int, int>::iterator it = MP.begin(); it != MP.end(); it++ ){
		ATI.push_back((*it).first);
		ATV.push_back((*it).second + ATV[pre++]);
	}

#ifdef DEBUG
print_acc_score();
#endif

	// ?????¨???????????????
	for(int i = 1; i <= Q; i++) {

		// ?????¨?????????????????????
		scanf("%s %d", query, &param);

		// 
		switch(query[0]) {
			case 'A':
				add(param);
#ifdef DEBUG
print_leaders();
#endif
				break;
			case 'R':
				del(param);
#ifdef DEBUG
print_leaders();
#endif
				break;
			default:
				bsearch(N - param);
				break;
		}
	}

	return 0;
}

Compiler output:
a.cc:54:2: error: expected unqualified-id before '/' token
   54 | */
      |  ^
a.cc: In function 'int main()':
a.cc:186:33: error: 'add' was not declared in this scope
  186 |                                 add(param);
      |                                 ^~~