Language: C++

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

int64_t maxsume(int a, int M, vector<int64_t>& Se, vector<int64_t>& So) {
  int64_t s = Se.at(M);
  for(int i=a;i<M/2;i++) {
    s = max(s, Se.at(M)-Se.at(i)+So.at(i));
    s = max(s, So.at(M-i)+Se.at(M)-Se.at(M-i));
  }
  if(M%2==0)
    s = max(s, So.at(M/2)+Se.at(M)-Se.at(M/2));
  return s;
}
  
int main() {
  int N;
  cin >> N;
  int M = N/2;
  vector<int64_t> A(N), Se(M+1,0), So(M+1,0);
  for(int i=0;i<N;i++)
    cin >> A.at(i);
  for(int i=0;i<M;i++) {
    Se.at(i+1) = Se.at(i) + A.at(i*2+1);
    So.at(i+1) = So.at(i) + A.at(i*2);
  }
  if(N%2==0)
    cout << maxsume(0, M, Se, So) << endl;
  else {
    vector<int64_t> Te(M+1,0), To(M+1,0);
    for(int i=0;i<M;i++) {
      Te.at(i+1) = Se.at(M-i);
      To.at(i+1) = To.at(i) + A.at(N-2*i);
    }
    int s = Se.at(M);
    for(int i=0;i<M/2;i++) {
      s = max(s, So.at(i)+To.at(i)+maxsume(i, M-i, Se, So));
      s = max(s, So.at(i)+To.at(i)+maxsume(i, M-i, Te, To));
    }
    cout << s << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:14: error: no matching function for call to 'max(int&, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
   36 |       s = max(s, So.at(i)+To.at(i)+maxsume(i, M-i, Se, So));
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/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:36:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   36 |       s = max(s, So.at(i)+To.at(i)+maxsume(i, M-i, Se, So));
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:
/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:36:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   36 |       s = max(s, So.at(i)+To.at(i)+maxsume(i, M-i, Se, So));
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:37:14: error: no matching function for call to 'max(int&, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
   37 |       s = max(s, So.at(i)+To.at(i)+maxsume(i, M-i, Te, To));
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:37:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   37 |       s = max(s, So.at(i)+To.at(i)+maxsume(i, M-i, Te, To));
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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
/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:37:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |       s = max(s, So.at(i)+To.at(i)+maxsume(i, M-i, Te, To));
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~