Language: C++

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;
ll N,Q;
ll A[100000],X[100000];
ll imos[100000],imos2[100000];

void calc(ll q){
  if(q <= A[1] ){
    cout<< imos[N - (N/2)] <<endl;
    return;
  }
  if(q >= (A[N-1] + A[N-2]) / 2){
    cout<< imos2[N-1] <<endl;
    return;
  }
  ll q_id = upper_bound(A,A+N,q) - A - 1;
  ll lb = q_id + 1,ub = N,mid;  //[lb,N)で独占
  while(ub-lb>1){
    mid=(ub+lb)/2; //mid以上で独占したと考える
    if(mid < N/2){
      lb=mid;
      continue;
    }
    ll dok_num = N-mid;
    if(q_id < mid-dok_num ){
      ub=mid;
      continue;
    }
    ll x = A[mid-dok_num];
    ll y = A[mid];
    if(y-q >= q-x && q-[mid-dok_num-1] >=  y-q) lb=mid;
    else ub=mid;
  }
  ll ans = imos[lb];
  ans += imos2[(N/2-lb)*2];
  // ll lb,ub,mid,q2,q2_id;
  // lb = -1;
  // ub = q_id;
  // while(ub-lb>1){
  //   mid = (ub+lb)/2; // midを最後に取るとmid-1を取られる
  //   q2 = q + (q-A[mid]) - 1; //midより小さいやつの最大値
  //   if(q2 >= A[N-1]) lb = mid;
  //   q2_id = upper_bound(A,A+N,q2) - A - 1; //q2の属するゾーン
  //   if( q2_id - mid + 1 > N - q2_id ) lb = mid;
  //   else ub = mid;
  // }
  // ll ans = 0;
  // if(ub<1)
  // ans += imos2[ub];
  // ans += imos[ q2_id + 1 ];
  cout<<ans<<endl;
}

int main(){
  cin>>N>>Q;
  rep(i,N) cin>>A[i];
  rep(i,Q) cin>>X[i];
  if(N%2 == 1){
    rrep(i,N){
      A[i+1]=A[i];
    }
    A[0] = -10000LL;
    N++;
  }
  imos[N-1]=A[N-1];
  rep1(i,N-1){
    imos2[i]=imos2[i-1];
    if(i%2) imos2[i]+=A[i];
  }
  rrep(i,N-1) imos[i] = imos[i+1] + A[i];
  rep(i,Q) calc(X[i]);
}


Compiler output:
a.cc: In function 'void calc(ll)':
a.cc:53:28: error: expected ',' before '-' token
   53 |     if(y-q >= q-x && q-[mid-dok_num-1] >=  y-q) lb=mid;
      |                            ^
      |                            ,
a.cc:53:28: error: expected identifier before '-' token
a.cc: In lambda function:
a.cc:53:40: error: expected '{' before '>=' token
   53 |     if(y-q >= q-x && q-[mid-dok_num-1] >=  y-q) lb=mid;
      |                                        ^~
a.cc: In function 'void calc(ll)':
a.cc:53:23: error: no match for 'operator-' (operand types are 'll' {aka 'long long int'} and 'calc(ll)::<lambda()>')
   53 |     if(y-q >= q-x && q-[mid-dok_num-1] >=  y-q) lb=mid;
      |                      ~^~~~~~~~~~~~~~~~
      |                      | |
      |                      | calc(ll)::<lambda()>
      |                      ll {aka long long int}
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:53:40: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'll' {aka 'long long int'}
   53 |     if(y-q >= q-x && q-[mid-dok_num-1] >=  y-q) lb=mid;
      |                                        ^~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:53:40: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'll' {aka 'long long int'}
   53 |     if(y-q >= q-x && q-[mid-dok_num-1] >=  y-q) lb=mid;
      |                                        ^~