Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <deque>
using namespace std;

deque<long long> V;
map<int, int> m;
int count = 0;
int max = -1;

int search(int K){
  if(K == 0){
    int sum = 0;
    for(auto itr=m.begin(); itr != m.end(); ++itr){
      if(itr->second != 0){
        sum += itr->first;
      }
    }
    return sum;
  }
  int ans = 0;
  if(V.size() != 0){
    int tmp = V.front();
    ++m[tmp];
    V.pop_front();
    ++count;
    ans = search(K-1);
    --m[tmp];
    V.push_front(tmp);
    --count;

    tmp = V.back();
    ++m[tmp];
    V.pop_back();
    ++count;
    ans = max(ans, search(K-1));
    --m[tmp];
    V.push_back(tmp);
    --count;
  }
  if(count != 0){
    int tmp;
    for(auto itr=m.begin(); itr != m.end(); ++itr){
      if(itr->second != 0){
        tmp = itr->first;
        break;
      }
    }
    --m[tmp];
    V.push_front(tmp);
    --count;
    ans = search(K-1);
    V.pop_front();
    V.push_back(tmp);
    ans = max(ans, search(K-1));
    V.pop_back();
    ++count;
    ++m[tmp];
  }
}

int main(void){
  int N, K;
  cin >> N >> K;
  V = vector<long long>(N);
  for(int cnt = 0; cnt < N; ++cnt){
    int v;
    cin >> v;
    V.push_back(v);
  }
  m = map<int, int>();
  count = 0;
  m[V.front()] = 1;
  V.pop_front();
  ++count;
  int ans = search(K-1);
  m = map<int, int>();
  count = 0;
  m[V.back()] = 1;
  V.pop_back();
  ++count;
  ans = max(ans, search(K-1));
  return 0;
}


Compiler output:
a.cc: In function 'int search(int)':
a.cc:31:7: error: reference to 'count' is ambiguous
   31 |     ++count;
      |       ^~~~~
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:7:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:13:5: note:                 'int count'
   13 | int count = 0;
      |     ^~~~~
a.cc:35:7: error: reference to 'count' is ambiguous
   35 |     --count;
      |       ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:13:5: note:                 'int count'
   13 | int count = 0;
      |     ^~~~~
a.cc:40:7: error: reference to 'count' is ambiguous
   40 |     ++count;
      |       ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:13:5: note:                 'int count'
   13 | int count = 0;
      |     ^~~~~
a.cc:41:11: error: reference to 'max' is ambiguous
   41 |     ans = max(ans, search(K-1));
      |           ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidates are: '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:5706:5: note:                 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
In file included from /usr/include/c++/14/string:51,
                 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:1:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:                 '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:14:5: note:                 'int max'
   14 | int max = -1;
      |     ^~~
a.cc:44:7: error: reference to 'count' is ambiguous
   44 |     --count;
      |       ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:13:5: note:                 'int count'
   13 | int count = 0;
      |     ^~~~~
a.cc:46:6: error: reference to 'count' is ambiguous
   46 |   if(count != 0){
      |      ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:13:5: note:                 'int count'
   13 | int count = 0;
      |     ^~~~~
a.cc:56:7: error: reference to 'count' is ambiguous
   56 |     --count;
      |       ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:13:5: note:                 'int count'
   13 | int count = 0;
      |     ^~~~~
a.cc:60:11: error: reference to 'max' is ambiguous
   60 |     ans = max(ans, search(K-1));
      |           ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidates are: '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:5706:5: note:                 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:                 '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:14:5: note:                 'int max'
   14 | int max = -1;
      |     ^~~
a.cc:62:7: error: reference to 'count' is ambiguous
   62 |     ++count;
      |       ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:13:5: note:                 'int count'
   13 | int count = 0;
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:70:26: error: no match for 'operator=' (operand types are 'std::deque<long long int>' and 'std::vector<long long int>')
   70 |   V = vector<long long>(N);
      |                          ^
In file included from /usr/include/c++/14/deque:69,
                 from a.cc:8:
/usr/include/c++/14/bits/deque.tcc:95:5: note: candidate: 'std::deque<_Tp, _Alloc>& std::deque<_Tp, _Alloc>::operator=(const std::deque<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
   95 |     deque<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/deque.tcc:96:28: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'const std: