Language: C++

#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

int main() {
  size_t N, Q;
  scanf("%zu %zu", &N, &Q);

  std::vector<intmax_t> A(N);
  for (auto& a_i: A) scanf("%jd", &a_i);

  std::vector<intmax_t> B(N);
  for (size_t i = 0; i < N; ++i) B[i] = A[N-i-1];

  std::vector<intmax_t> X(Q);
  for (auto& x_i: X) scanf("%jd", &x_i);

  intmax_t less = 0;
  for (size_t i = 0; i < (N+1)/2; ++i) less += B[i];
  intmax_t greater = 0;
  for (size_t i = 0; i < N; i += 2) greater += B[i];

  std::vector<intmax_t> seq(N+1);
  for (size_t i = 0; i < N; ++i)
    seq[i+1] = seq[i] + B[i];

  std::vector<intmax_t> skip(N+1);
  skip[1] = A[0];
  skip[2] = A[1];
  for (size_t i = 2; i < N; ++i)
    skip[i+1] = skip[i-1] + A[i];

  for (size_t i = 0; i <= N; ++i)
    fprintf(stderr, "%jd%c", seq[i], i<N? ' ':'\n');
  for (size_t i = 0; i <= N; ++i)
    fprintf(stderr, "%jd%c", skip[i], i<N? ' ':'\n');

  std::vector<intmax_t> taka((N+1)/2);
  for (size_t i = 0; i < (N+1)/2; ++i) {
    size_t j = i+i;
    if (N % 2 > 0 && j > 0) --j;
    taka[i] = seq[(N+1)/2-i] + skip[j];
  }
  for (size_t i = 0; i < (N+1)/2; ++i)
    fprintf(stderr, "%jd%c", taka[i], i+1<(N+1)/2? ' ':'\n');

  std::vector<intmax_t> C(N);
  for (size_t i = 1; i < N; ++i)
    C[i] = (A[i] + A[i-1]) / 2 + (N+1+i)%2;

  for (size_t i = 0; i < N; ++i)
    fprintf(stderr, "%jd%c", C[i], i+1<N? ' ':'\n');

  for (size_t i = 0; i < Q; ++i) {
    if (N == 2) {
      printf("%jd\n", B[0]);
      continue;
    }

    intmax_t x = X[i];
    if (x <= (A[0]+A[N/2]) / 2) {
      printf("%jd\n", less);
      continue;
    }
    if (x > (B[1]+B[2]) / 2) {
      printf("%jd\n", greater);
      continue;
    }

    auto it = std::upper_bound(C.begin(), C.end(), x);
    intmax_t d = (it - C.begin());
    intmax_t j = std::max(std::min(d-N/2, (N+1)/2-1), 0);
    fprintf(stderr, "x: %jd, [%jd]: %jd\n", x, d-N/2, taka[d-N/2]);
    printf("%jd\n", taka[j]);
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:73:26: error: no matching function for call to 'max(const long unsigned int&, int)'
   73 |     intmax_t j = std::max(std::min(d-N/2, (N+1)/2-1), 0);
      |                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:3:
/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:73:26: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
   73 |     intmax_t j = std::max(std::min(d-N/2, (N+1)/2-1), 0);
      |                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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,
                 from a.cc:4:
/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:73:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   73 |     intmax_t j = std::max(std::min(d-N/2, (N+1)/2-1), 0);
      |                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~