Language: C++

#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;


int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(), a.end());
    int com=0;
    vector<int> count2(n,0);
    count2.at(0)=a.at(0);
    count2.at(1)=a.at(1);
    com+=a.at(0);


    for (int i = 2; i < 19; i++)
    {
        int aa=1;
        int bb;

        for (int j = 0; j < i; j++)
        {
            aa=aa*2; 
        }
        bb=aa/2;

        
        if(n>=aa){
            for (int i = bb; i < aa-1; i++)
            {
                com+=min(count2.at(i-bb,count2.at(i-bb+1));
            }
            com+=count2.at(bb-1);
            for (int i = aa-1; i > bb-1; i--)
            {
                count2.insert(count2.begin()+i-bb+1,a.at(i));
            }            
        }else if(n>bb)
        {
            for (int i = bb; i < n; i++)
            {
                com+=min(count2.at(i-bb,count2.at(i-bb+1));
            }
            cout<<com<<endl;
        }



    }

    

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:35: error: no matching function for call to 'std::vector<int>::at(int, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   46 |                 com+=min(count2.at(i-bb,count2.at(i-bb+1));
      |                          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_vector.h:1180:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1180 |       at(size_type __n)
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1180:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1199:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::at(size_type) const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&; size_type = long unsigned int]'
 1199 |       at(size_type __n) const
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1199:7: note:   candidate expects 1 argument, 2 provided
a.cc:57:35: error: no matching function for call to 'std::vector<int>::at(int, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   57 |                 com+=min(count2.at(i-bb,count2.at(i-bb+1));
      |                          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1180:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1180 |       at(size_type __n)
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1180:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1199:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::at(size_type) const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&; size_type = long unsigned int]'
 1199 |       at(size_type __n) const
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1199:7: note:   candidate expects 1 argument, 2 provided