Language: C++

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

#define int long long
#define MOD (int)(1e9 + 7)

using namespace std;

signed main()
{
    int N, K;
    cin >> N >> K;
    int n_zero = 0;
    priority_queue<int> p, m;
    priority_queue<int,vector<int>,greater<int>()> all;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        if (x == 0)
        {
            n_zero++;
        }
        else if (x > 0)
        {
            p.push(x);
        }
        else
        {
            m.push(-x);
        }
        all.push(x);
    }

    if (N - n_zero < K)
    {
        cout << 0 << endl;
        return 0;
    }

    // possible to make positive ans
    if (m.size() + 2 * p.size() >= 2*K)
    {
        int ans = 1;
        if (K % 2 == 1 && !p.empty())
        {
            ans = p.top();
            p.pop();
            K--;
        }

        priority_queue<int> mul;
        while (p.size() >= 2)
        {
            int x = p.top();
            p.pop();
            x *= p.top();
            p.pop();
            //x %= MOD;
            mul.push(x);
        }
        if (!p.empty())
        {
            mul.push(p.top());
        }
        while (m.size() >= 2)
        {
            int x = m.top();
            m.pop();
            x *= m.top();
            m.pop();
            //x %= MOD;
            mul.push(x);
        }
        for (int i = 0; i < K / 2; i++)
        {
            ans *= (mul.top() % MOD );
            mul.pop();
            ans %= MOD;
        }
        cout << ans << endl;
    }
    else
    {
        if (n_zero > 0)
        {
            cout << 0 << endl;
            return 0;
        }
        int ans = 1;
        vector<int> v;
        while (!p.empty())
        {
            int x = p.top();
            p.pop();
            v.push_back(x);
        }
        while (!m.empty())
        {
            int x = m.top();
            m.pop();
            v.push_back(x);
        }
        sort(v.begin(), v.end());
        for (int i = 0; i < K; i++)
        {
            ans *= v[i];
            ans %= MOD;
        }
        cout << (-ans + MOD) << endl;
    }
    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_queue.h: In instantiation of 'class std::priority_queue<long long int, std::vector<long long int, std::allocator<long long int> >, std::greater<long long int>()>':
a.cc:17:52:   required from here
   17 |     priority_queue<int,vector<int>,greater<int>()> all;
      |                                                    ^~~
/usr/include/c++/14/bits/stl_queue.h:538:18: error: data member 'std::priority_queue<long long int, std::vector<long long int, std::allocator<long long int> >, std::greater<long long int>()>::comp' invalidly declared function type
  538 |       _Compare   comp;
      |                  ^~~~
a.cc: In function 'int main()':
a.cc:17:52: error: no matching function for call to 'std::priority_queue<long long int, std::vector<long long int, std::allocator<long long int> >, std::greater<long long int>()>::priority_queue()'
   17 |     priority_queue<int,vector<int>,greater<int>()> all;
      |                                                    ^~~
/usr/include/c++/14/bits/stl_queue.h:691:9: note: candidate: 'template<class _InputIterator, class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, _Sequence&&, const _Alloc&) [with _Alloc = _InputIterator; _Requires = _Alloc; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  691 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:691:9: note:   candidate expects 5 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:679:9: note: candidate: 'template<class _InputIterator, class _Alloc, class, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, const _Sequence&, const _Alloc&) [with _Alloc = _InputIterator; <template-parameter-2-3> = _Alloc; _Requires = <template-parameter-1-3>; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  679 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:679:9: note:   candidate expects 5 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:671:9: note: candidate: 'template<class _InputIterator, class _Alloc, class, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, const _Alloc&) [with _Alloc = _InputIterator; <template-parameter-2-3> = _Alloc; _Requires = <template-parameter-1-3>; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  671 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:671:9: note:   candidate expects 4 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:663:9: note: candidate: 'template<class _InputIterator, class _Alloc, class, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Alloc&) [with _Alloc = _InputIterator; <template-parameter-2-3> = _Alloc; _Requires = <template-parameter-1-3>; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  663 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:663:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:649:9: note: candidate: 'template<class _InputIterator, class> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, _Sequence&&) [with <template-parameter-2-2> = _InputIterator; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  649 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:649:9: note:   candidate expects 4 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:638:9: note: candidate: 'template<class _InputIterator, class> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, const _Sequence&) [with <template-parameter-2-2> = _InputIterator; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  638 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:638:9: note:   candidate expects 4 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:629:9: note: candidate: 'template<class _InputIterator, class> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&) [with <template-parameter-2-2> = _InputIterator; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  629 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:629:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:594:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(std::priority_queue<_Tp, _Sequence, _Compare>&&, const _Alloc&) [with _Requires = _Alloc; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  594 |         priority_queue(priority_queue&& __q, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:594:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:590:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const std::priority_queue<_Tp, _Sequence, _Compare>&, const _Alloc&) [with _Requires = _Alloc; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  590 |         priority_queue(const priority_queue& __q, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:590:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:585:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, _Sequence&&, const _Alloc&) [with _Requires = _Alloc; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  585 |         priority_queue(const _Compare& __x, _Sequence&& __c, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:585:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:579:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Sequence&, const _Alloc&) [with _Requires = _Alloc; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  579 |         priority_queue(const _Compare& __x, const _Sequence& __c,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:579:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:573:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Alloc&) [with _Requires = _Alloc; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  573 |         priority_queue(const _Compare& __x, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:573:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:569:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Alloc&) [with _Requires = _Alloc; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  569 |         priority_queue(const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:569:9: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_queue.h:554:9: note: candidate: 'template<class _Seq, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue() [with _Requires = _Seq; _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  554 |         priority_queue()
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:554:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_queue.h:551:43: error: no type named 'type' in 'struct std::enable_if<false, void>'
  551 |       template<typename _Seq = _Sequence, typename _Requires = typename
      |                                           ^~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:563:7: note: candidate: 'std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, _Sequence&&) [with _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::greater<long long int>()]'
  563 |       priority_queue(const _Compare& __x, _Sequence&& __s = _Sequence())
      |       ^~~~~~~~~~~~~~
/usr/include/c++