Language: C++

#include<bits/stdc++.h>
using namespace std;
#define SORT(A) std::sort(A.begin(), A.end())
#define RSORT(A) std::sort(A.begin(), A.end(), std::greater<>())
#define FR(A, e) for (auto& e : A)
#define SHOW(A) for (auto& e : A) {cout << e << " ";}; cout << endl;
#define within(x,_left,_right) (_left <= x && x <= _right)
#define rwithin(x, _l, _r) (_l < x && x < _r)
#define ALL(A) A.begin(),A.end()
#define RALL(A) (A).rbegin(),(A).rend()
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define sz(x) ((int)x.size())
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define bitcnt(x) (__builtin_popcountll(x))
#define fi first
#define se second
#define bg(A) A.begin()
#define ed(A) A.end()
#define rbg(A) A.rbegin()
#define red(A) A.rend()
using LL = long long;
using db = double;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VL = vector<LL>;
using VVL = vector<VL>;
const LL MOD = 1e9 + 7;
const LL LMAX = 0x7fffffffffffffff;
const LL LMIN = 0x8000000000000000;
typedef std::pair<int, int> PII;
typedef std::pair<LL, LL> PLL;
typedef std::pair<int, char> PIC;
// int dx[4] = {1, -1, 0, 0}; // 冯诺依曼型邻居
// int dy[4] = {0, 0, 1, -1};
// int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; // 摩尔型邻居
// int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
// #include<iomanip> cout << fixed <<  setprecision(k) 输出k位精度

int N, K;
VI pos, neg, zero;

void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    std::cin >> N >> K;

    pos.clear(), neg.clear(), zero.clear();

    int t;
    for (int i = 0; i < N; ++ i){
        cin >> t;
        if (t > 0) pos.emplace_back(t);
        else if (t == 0) zero.emplace_back(t);
        else neg.emplace_back(t);
    }

    RSORT(pos);
    SORT(neg);

    int a = sz(pos), b = sz(neg), c = sz(zero);
    LL res = 1;

    if (a + b < K){
        cout << 0 << endl;
        return 0;
    }

    if (a + b == K){
        if ((b & 1) && c != 0){
            cout << 0 << endl;
        }else {
            for (auto &x: pos) res = (res * 1LL * x) % MOD;
            for (auto &x: neg) res = ((res * 1LL * x) + MOD) % MOD;
            cout << (res + MOD) % MOD << endl;
        }
        return 0;
    }

    int pp = 0, pn = 0;
    LL pmax, nmax;
    if ((K & 1) && a != 0){
        res = (1LL * res * pos[pp++]) % MOD;
        -- K;
    }
    else if ((K & 1) && a == 0){
        for (int i = 0, x = 0; i < K; ++ i) x = neg[b - 1 - i], res = ((res * 1LL * x) + MOD) % MOD;
        cout << (res + MOD) % MOD << endl;
        return 0;
    }

    while (K){
        pmax = 0, nmax = 0;
        if (pp + 1 < a) pmax = (1LL * pos[pp] * pos[pp + 1]) % MOD;
        if (pn + 1 < b)  nmax = (1LL * neg[pn] * neg[pn + 1]) % MOD;

        if (pmax > nmax){
            // res = (1LL * res * pmax) % MOD;
            mul(res, pmax % MOD);
            pp += 2;
        }else {
            // res = (1LL * res * nmax) % MOD;
            mul(res, nmax % MOD);
            pn += 2;
        }
        K -= 2;
    }

    cout << (res + MOD) % MOD << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:103:17: error: cannot bind non-const lvalue reference of type 'int64_t&' {aka 'long int&'} to a value of type 'LL' {aka 'long long int'}
  103 |             mul(res, pmax % MOD);
      |                 ^~~
a.cc:45:19: note:   initializing argument 1 of 'void mul(int64_t&, int64_t)'
   45 | void mul(int64_t& a, int64_t b){
      |          ~~~~~~~~~^
a.cc:107:17: error: cannot bind non-const lvalue reference of type 'int64_t&' {aka 'long int&'} to a value of type 'LL' {aka 'long long int'}
  107 |             mul(res, nmax % MOD);
      |                 ^~~
a.cc:45:19: note:   initializing argument 1 of 'void mul(int64_t&, int64_t)'
   45 | void mul(int64_t& a, int64_t b){
      |          ~~~~~~~~~^