Language: C++

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

int main() {
  int A,B,Q;
  cin >> A >> B >> Q;
  vector<long> a(A);
  vector<long> b(B);
  for(int i=0;i<A;i++)cin >> a[i];
  for(int i=0;i<B;i++)cin >> b[i];
  for(int i=0;i<Q;i++){
    long x;
    cin >> x;
    auto ia=lower_bound(a.begin(),a.end(),x);
    auto ib=lower_bound(b.begin(),b.end(),x);
    int p,q,r,s;
    p=min(a[ia]-x,b[ib]-x);
    ib--;
    q=min(2*(a[ia]-x)+x-b[ib],a[ia]-x+2*(x-b[ib]));
    ia--;
    ib++;
    r=min(2*(x-a[ia])+b[ib]-x,x-a[ia]+2*(b[ib]-x));
    ib--;
    s=min(x-a[ia],x-b[ib]);
    cout << min({p,q,r,s}) << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:12: error: no match for 'operator[]' (operand types are 'std::vector<long int>' and '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >')
   17 |     p=min(a[ia]-x,b[ib]-x);
      |            ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long int; _Alloc = std::allocator<long int>; reference = long int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long int; _Alloc = std::allocator<long int>; const_reference = const long int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:17:20: error: no match for 'operator[]' (operand types are 'std::vector<long int>' and '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >')
   17 |     p=min(a[ia]-x,b[ib]-x);
      |                    ^
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long int; _Alloc = std::allocator<long int>; reference = long int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long int; _Alloc = std::allocator<long int>; const_reference = const long int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:19:15: error: no match for 'operator[]' (operand types are 'std::vector<long int>' and '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >')
   19 |     q=min(2*(a[ia]-x)+x-b[ib],a[ia]-x+2*(x-b[ib]));
      |               ^
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long int; _Alloc = std::allocator<long int>; reference = long int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long int; _Alloc = std::allocator<long int>; const_reference = const long int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:19:26: error: no match for 'operator[]' (operand types are 'std::vector<long int>' and '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >')
   19 |     q=min(2*(a[ia]-x)+x-b[ib],a[ia]-x+2*(x-b[ib]));
      |                          ^
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long int; _Alloc = std::allocator<long int>; reference = long int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long int; _Alloc = std::allocator<long int>; const_reference = const long int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:19:32: error: no match for 'operator[]' (operand types are 'std::vector<long int>' and '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >')
   19 |     q=min(2*(a[ia]-x)+x-b[ib],a[ia]-x+2*(x-b[ib]));
      |                                ^
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long int; _Alloc = std::allocator<long int>; reference = long int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long int; _Alloc = std::allocator<long int>; const_reference = const long int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:19:45: error: no match for 'operator[]' (operand types are 'std::vector<long int>' and '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >')
   19 |     q=min(2*(a[ia]-x)+x-b[ib],a[ia]-x+2*(x-b[ib]));
      |                                             ^
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long int; _Alloc = std::allocator<long int>; reference = long int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long int; _Alloc = std::allocator<long int>; const_reference = const long int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >' to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:22:17: error: no match for 'operator[]' (operand types are 'std::vector<long int>' and '__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >')
   22 |     r=min(2*(x-a[ia])+b[ib]-x,x-a[ia]+2*(b[ib]-x));
      |                 ^
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::