Language: C++

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n,m; cin >>n>>m;
    vll a(n); rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int res = m, j= 0;
    for(int i = 0; res > 0 && i < n;){
        auto itr = max_element(a.begin(), a.at(i));
        if(a[i] <= *itr){
            swap(a.at(i), *itr);
        }
       int p = a[i]; p /= 2; a[i] = p;
        res--;
        i++;
    }

    ll counting = 0;
    rep(i,n){
        counting += a[i];
    }
    cout << counting << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:31: error: no matching function for call to 'max_element(std::vector<long long int>::iterator, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
   30 |         auto itr = max_element(a.begin(), a.at(i));
      |                    ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:5641:5: note: candidate: 'template<class _FIter> constexpr _FIter std::max_element(_FIter, _FIter)'
 5641 |     max_element(_ForwardIterator __first, _ForwardIterator __last)
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5641:5: note:   template argument deduction/substitution failed:
a.cc:30:31: note:   deduced conflicting types for parameter '_FIter' ('__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' and 'long long int')
   30 |         auto itr = max_element(a.begin(), a.at(i));
      |                    ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5666:5: note: candidate: 'template<class _FIter, class _Compare> constexpr _FIter std::max_element(_FIter, _FIter, _Compare)'
 5666 |     max_element(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5666:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:524:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::max_element(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Compare)'
  524 | max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp);
      | ^~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:524:1: note:   candidate expects 4 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:528:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::max_element(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator)'
  528 | max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
      | ^~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:528:1: note:   candidate expects 3 arguments, 2 provided