Language: C++

/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define mod  1000000007LL
#define PI 2*acos(0.0)

vll inp;
int n, m;

bool bnok(int j)
{
    int lo = 0, hi = j-1, mid, pos = -1;
    while(lo <= hi)
    {
        mid = (lo + hi)/2;
        if(inp[mid] + inp[j] >= m)
        {
            pos = mid;
            hi = mid-1;
        }
        else
            lo = mid+1;
    }
    return pos != -1;
}

int32_t main()
{
    io;
    cin>>n>>m;
    for(int i = 0; i < 2*n; i++)
    {
        int x;
        cin>>x;
        inp.pb(x);
    }
    sort(inp.begin(), inp.end());
    int j = 2*n-1, cnt = 0;
    while(bnok(j))
    {
        cnt++;
        j--;
    }
    int isec = 2*n - 2*cnt, ans = INT_MIN, esec = 2*n-1, sf = 0, ef = 2*n- 2*cnt - 1;
    while(isec < esec)
    {
        ans = max(ans, (inp[isec] + inp[esec])%m);
        isec++;
        esec--;
    }
    while(sf < ef)
    {
        ans = max(ans, (inp[sf] + inp[ef])%m);
        sf++;
        ef--;
    }
    cout<<ans;
    return 0;
}


Compiler output:
a.cc: In function 'int32_t main()':
a.cc:58:18: error: no matching function for call to 'max(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   58 |         ans = max(ans, (inp[isec] + inp[esec])%m);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:5:
/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:58:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   58 |         ans = max(ans, (inp[isec] + inp[esec])%m);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:58:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   58 |         ans = max(ans, (inp[isec] + inp[esec])%m);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:64:18: error: no matching function for call to 'max(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   64 |         ans = max(ans, (inp[sf] + inp[ef])%m);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:64:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   64 |         ans = max(ans, (inp[sf] + inp[ef])%m);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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
/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:64:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   64 |         ans = max(ans, (inp[sf] + inp[ef])%m);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~