Language: C++

#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long ll;
int A, B, Q;

void solve(ll x, vector<ll> s, vector<ll> t) {
   ll ans = -1;
   int its = lower_bound(s.begin(), s.end(), x) - s.begin();
   int itt = lower_bound(t.begin(), t.end(), x) - t.begin();
   ll tmp;
   /*
   if (its - s.begin() != A && itt - t.begin() != B) {
      tmp = max(abs(s[its - s.begin()] - x), abs(t[itt - t.begin()] - x));
      if (ans == -1) ans = tmp;
      else ans = min(ans, tmp);
   }
   if (its - s.begin() - 1 >= 0 && itt - t.begin() - 1 >= 0) {
      tmp = max(abs(s[its - s.begin() - 1] - x), abs(t[itt - t.begin() - 1] - x));
      if (ans == -1) ans = tmp;
      else ans = min(ans, tmp);
   }
   if (itt - t.begin() - 1 >= 0 && its - s.begin() != A) {
      tmp = abs(s[its - s.begin()] - x) * 2 + abs(t[itt - t.begin() - 1] - x);
      if (ans == -1) ans = tmp;
      else ans = min(ans, tmp);
      tmp = abs(s[its - s.begin()] - x) + abs(t[itt - t.begin() - 1] - x) * 2;
      if (ans == -1) ans = tmp;
      else ans = min(ans, tmp);
   }
   if (its - s.begin() - 1 >= 0 && itt - t.begin() != B) {
      tmp = abs(t[itt - t.begin()] - x) * 2 + abs(s[its - s.begin() - 1] - x);
      if (ans == -1) ans = tmp;
      else ans = min(ans, tmp);
      tmp = abs(t[itt - t.begin()] - x) + abs(s[its - s.begin() - 1] - x) * 2;
      if (ans == -1) ans = tmp;
      else ans = min(ans, tmp);
   }
   */
   cout << ans << endl;
}

int main() {
   ll x;
   cin >> A >> B >> Q;
   vector<ll> s;
   vector<ll> t;
   ll tmp;
   for (int a = 0; a < A; a++) {
      cin >> tmp;
      s.push_back(tmp);
   }
   for (int b = 0; b < B; b++) {
      cin >> tmp;
      t.push_back(tmp);
   }
   for (int q = 0; q < Q; q++) {
      cin >> x;
      ll ans = -1;
      decltype(s)::iterator its = lower_bound(s.begin(), s.end(), x) - s.begin();
      decltype(t)::iterator itt = lower_bound(t.begin(), t.end(), x) - t.begin();
      ll tmp;
      
      if (its - s.begin() != A && itt - t.begin() != B) {
         tmp = max(abs(s[its - s.begin()] - x), abs(t[itt - t.begin()] - x));
         if (ans == -1) ans = tmp;
         else ans = min(ans, tmp);
      }
      if (its - s.begin() - 1 >= 0 && itt - t.begin() - 1 >= 0) {
         tmp = max(abs(s[its - s.begin() - 1] - x), abs(t[itt - t.begin() - 1] - x));
         if (ans == -1) ans = tmp;
         else ans = min(ans, tmp);
      }
      if (itt - t.begin() - 1 >= 0 && its - s.begin() != A) {
         tmp = abs(s[its - s.begin()] - x) * 2 + abs(t[itt - t.begin() - 1] - x);
         if (ans == -1) ans = tmp;
         else ans = min(ans, tmp);
         tmp = abs(s[its - s.begin()] - x) + abs(t[itt - t.begin() - 1] - x) * 2;
         if (ans == -1) ans = tmp;
         else ans = min(ans, tmp);
      }
      if (its - s.begin() - 1 >= 0 && itt - t.begin() != B) {
         tmp = abs(t[itt - t.begin()] - x) * 2 + abs(s[its - s.begin() - 1] - x);
         if (ans == -1) ans = tmp;
         else ans = min(ans, tmp);
         tmp = abs(t[itt - t.begin()] - x) + abs(s[its - s.begin() - 1] - x) * 2;
         if (ans == -1) ans = tmp;
         else ans = min(ans, tmp);
      }
      cout << ans << endl;
   }
   return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:70: error: conversion from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'} to non-scalar type 'std::vector<long long int>::iterator' requested
   67 |       decltype(s)::iterator its = lower_bound(s.begin(), s.end(), x) - s.begin();
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
a.cc:68:70: error: conversion from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'} to non-scalar type 'std::vector<long long int>::iterator' requested
   68 |       decltype(t)::iterator itt = lower_bound(t.begin(), t.end(), x) - t.begin();
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~