Language: C++

#include<bits/stdc++.h>
using namespace std;

int N, Q, s[1000000];
vector< int > Student;
multiset< int > Leader;

bool Check(int value, int x)
{
  vector< int >::iterator last = Student.begin();
  int Lost = 0;
  for(multiset< int >::iterator it = Leader.begin(); it != Leader.end() && last != Student.end(); ++it) {
    Lost += lower_bound(last, Student.end(), *it - value) - last;
    last = upper_bound(last, Student.end(), *it);
  }
  Lost += max(0, Student.end() - last);
  return(Lost <= x);
}
int BinarySearch(int Lower, int Upper, int x)
{
  int Mid = (Lower + Upper) >> 1;
  if(Lower >= Upper) return(Lower);
  if(Check(Mid, x)) return(BinarySearch(Lower, Mid, x));
  return(BinarySearch(Mid + 1, Upper, x));
}
main()
{
  cin >> N >> Q;
  Student.resize(N);
  for(int i = 0; i < N; ++i) {
    cin >> Student[i];
    s[i] = Student[i];
  }
  sort(Student.begin(), Student.end());
  while(Q--) {
    string Query;
    int a;
    cin >> Query >> a;
    if(Query[0] == 'A') { // "ADD"
      Leader.insert(s[--a]);
    } else if(Query[0] == 'R') { // "REMOVE"
      Leader.erase(Leader.find(s[--a]));
    } else { // "CHECK"
      int ret = BinarySearch(0, 1 << 30, a);
      if(ret == 1 << 30) cout << "NA" << endl;
      else cout << ret << endl;
    }
  }
}

Compiler output:
a.cc: In function 'bool Check(int, int)':
a.cc:16:14: error: no matching function for call to 'max(int, __gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'
   16 |   Lost += max(0, Student.end() - last);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:16:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'})
   16 |   Lost += max(0, Student.end() - last);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:16:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   16 |   Lost += max(0, Student.end() - last);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: At global scope:
a.cc:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main()
      | ^~~~