Language: C++

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007;
const int MAX = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  int n, sum = 0, check = 1, flag = 0;
  cin >> n;
  vector<int> a(n);
  queue<int> q(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  for (int i = 0; i < n; i++) {
    q.push(a[i]);
    sum += q.top();
    if (flag == 0) {
      if (i == 1) {
        q.pop();
      } else {
        flag = 1;
      }
    } else {
      flag = 0;
      q.pop();
    }
  }
  cout << sum << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:17: error: no matching function for call to 'std::queue<int>::queue(int&)'
   13 |   queue<int> q(n);
      |                 ^
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_queue.h:195:9: note: candidate: 'template<class _Alloc, class _Requires> std::queue<_Tp, _Sequence>::queue(std::queue<_Tp, _Sequence>&&, const _Alloc&) [with _Requires = _Alloc; _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]'
  195 |         queue(queue&& __q, const _Alloc& __a)
      |         ^~~~~
/usr/include/c++/14/bits/stl_queue.h:195:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_queue.h:191:9: note: candidate: 'template<class _Alloc, class _Requires> std::queue<_Tp, _Sequence>::queue(const std::queue<_Tp, _Sequence>&, const _Alloc&) [with _Requires = _Alloc; _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]'
  191 |         queue(const queue& __q, const _Alloc& __a)
      |         ^~~~~
/usr/include/c++/14/bits/stl_queue.h:191:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_queue.h:187:9: note: candidate: 'template<class _Alloc, class _Requires> std::queue<_Tp, _Sequence>::queue(_Sequence&&, const _Alloc&) [with _Requires = _Alloc; _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]'
  187 |         queue(_Sequence&& __c, const _Alloc& __a)
      |         ^~~~~
/usr/include/c++/14/bits/stl_queue.h:187:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_queue.h:183:9: note: candidate: 'template<class _Alloc, class _Requires> std::queue<_Tp, _Sequence>::queue(const _Sequence&, const _Alloc&) [with _Requires = _Alloc; _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]'
  183 |         queue(const _Sequence& __c, const _Alloc& __a)
      |         ^~~~~
/usr/include/c++/14/bits/stl_queue.h:183:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_queue.h:179:9: note: candidate: 'template<class _Alloc, class _Requires> std::queue<_Tp, _Sequence>::queue(const _Alloc&) [with _Requires = _Alloc; _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]'
  179 |         queue(const _Alloc& __a)
      |         ^~~~~
/usr/include/c++/14/bits/stl_queue.h:179:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_queue.h: In substitution of 'template<class _Tp, class _Sequence> template<class _Alloc> using std::queue<_Tp, _Sequence>::_Uses = typename std::enable_if<std::uses_allocator<_Sequence, _Alloc>::value>::type [with _Alloc = int; _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]':
/usr/include/c++/14/bits/stl_queue.h:177:33:   required from here
  177 |       template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
      |                                 ^~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:125:15: error: no type named 'type' in 'struct std::enable_if<false, void>'
  125 |         using _Uses = typename
      |               ^~~~~
/usr/include/c++/14/bits/stl_queue.h:166:9: note: candidate: 'template<class _Seq, class _Requires> std::queue<_Tp, _Sequence>::queue() [with _Requires = _Seq; _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]'
  166 |         queue()
      |         ^~~~~
/usr/include/c++/14/bits/stl_queue.h:166:9: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_queue.h:174:7: note: candidate: 'std::queue<_Tp, _Sequence>::queue(_Sequence&&) [with _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]'
  174 |       queue(_Sequence&& __c)
      |       ^~~~~
/usr/include/c++/14/bits/stl_queue.h:174:25: note:   no known conversion for argument 1 from 'int' to 'std::deque<int, std::allocator<int> >&&'
  174 |       queue(_Sequence&& __c)
      |             ~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:170:7: note: candidate: 'std::queue<_Tp, _Sequence>::queue(const _Sequence&) [with _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]'
  170 |       queue(const _Sequence& __c)
      |       ^~~~~
/usr/include/c++/14/bits/stl_queue.h:170:30: note:   no known conversion for argument 1 from 'int' to 'const std::deque<int, std::allocator<int> >&'
  170 |       queue(const _Sequence& __c)
      |             ~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:96:11: note: candidate: 'std::queue<int>::queue(const std::queue<int>&)'
   96 |     class queue
      |           ^~~~~
/usr/include/c++/14/bits/stl_queue.h:96:11: note:   no known conversion for argument 1 from 'int' to 'const std::queue<int>&'
/usr/include/c++/14/bits/stl_queue.h:96:11: note: candidate: 'std::queue<int>::queue(std::queue<int>&&)'
/usr/include/c++/14/bits/stl_queue.h:96:11: note:   no known conversion for argument 1 from 'int' to 'std::queue<int>&&'
a.cc:20:14: error: 'class std::queue<int>' has no member named 'top'; did you mean 'pop'?
   20 |     sum += q.top();
      |              ^~~
      |              pop