Language: C++


#include <iostream>
#include <string>
#include <vector>

using namespace std;
void tbd(){

    string s; cin >> s;
    int month = stoi( s.substr(5,2) );
    int day = stoi( s.substr(8,2) );
    if (month >= 5){
        cout << "TBD" << endl;
    }else{
        cout << "Heisei" << endl;
    }

}

void gift(){
    int N; cin >> N;
    double bit_sum = 0.0;
    int jpy_sum = 0;

    for(int i= 0; i < N; i++){
        string x_i,u_i; cin >> x_i >> u_i;

        if( u_i == "JPY"){
            jpy_sum += stoi(x_i);
        }else if( u_i == "BTC"){
            bit_sum += stod(x_i);
        }
    }

    double ans;
    ans = 380000.0 * bit_sum + static_cast<double>(jpy_sum);

    cout << ans;



}

template<typename T>
pair<T, T> find(T x, const vector<T>& vec, int st, int ed){

    if(x < vec[st])
        return {-1,0};
    if( vec[ed] < x)
        return {ed, -1};

    while(ed - st > 1){

        int mid = (ed + st)/2;
        if(vec[mid] > x ){
            ed = mid;
        }else{
            st = mid;
        }
    }

    return {st, ed};

}


long long find_min(long long x, const vector<long long>& s_vec, const vector<long long>& t_vec, int A, int B){
    auto s_pair = find(x, s_vec, 0, A-1);
    auto t_pair = find(x, t_vec, 0, B-1);

    long long ss[2] = {s_pair.first, s_pair.second};
    long long tt[2] = {t_pair.first, t_pair.second};

    long long ans = numeric_limits<long long>::max();

    for(int i = 0; i<2; i++) {
        if (ss[i] == -1 )
            continue;
        for (int j = 0; j < 2; j++) {
            if (tt[j] == -1)
                continue;
            long long to_s = abs(x - s_vec[ss[i]]);
            long long to_t = abs(x - t_vec[tt[j]]);

            if (i == j) {//同じ方角
                long long dist = max(to_s, to_t);
                ans = (ans < dist) ? ans : dist;
            } else {
                long long dist;
                if (to_s > to_t){
                    dist = 2 * to_t + to_s;
                } else {
                    dist = 2 * to_s + to_t;
                }
                ans = (ans < dist) ? ans : dist;
            }


        }
    }

    return ans;

}

void lazy(){

    int A,B,Q; cin >> A >> B >> Q;
    vector<long long> s_vec(A);
    vector<long long> t_vec(B);
    vector<long long> x_vec(Q);
    for(int i = 0; i < A; i++){
        cin >> s_vec[i];
    }
    for(int i = 0; i < B; i++){
        cin >> t_vec[i];
    }
    for(int i = 0; i < Q; i++){
        cin >> x_vec[i];
    }

    sort(s_vec.begin(), s_vec.end() );
    sort(t_vec.begin(), t_vec.end() );
    for(int i = 0; i < Q; i++){
        cout << find_min(x_vec[i], s_vec, t_vec, A, B) << endl;
    }
}

int main(){

    lazy();
    return 0;
}

Compiler output:
a.cc: In function 'long long int find_min(long long int, const std::vector<long long int>&, const std::vector<long long int>&, int, int)':
a.cc:74:21: error: 'numeric_limits' was not declared in this scope
   74 |     long long ans = numeric_limits<long long>::max();
      |                     ^~~~~~~~~~~~~~
a.cc:74:36: error: expected primary-expression before 'long'
   74 |     long long ans = numeric_limits<long long>::max();
      |                                    ^~~~
a.cc: In function 'void lazy()':
a.cc:122:5: error: 'sort' was not declared in this scope; did you mean 'short'?
  122 |     sort(s_vec.begin(), s_vec.end() );
      |     ^~~~
      |     short