Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll inv(ll a){
    return modpow(a, MOD - 2, MOD);
}
int main() {
    init();
    ll N,K;
    cin >> N >> K;
    vl A(N);
    rep(i, N) cin >> A[i];

    vl M, P;
    ll z = 0;
    sort(all(A));
    rep(i, N){
        if (A[i] == 0) z++;
        else if(A[i]<0)
            M.eb(A[i]);
        else
            P.eb(A[i]);
    }

    ll mn = M.size(), pn = P.size();

    if(K+z>N or (z>0 and K+z==N and mn%2)){
        cout << 0 << endl;
        return 0;
    }
    else if(pn == 0 and K%2){
        if(z>0){
            cout << 0 << endl;
        }
        else{
            ll ans = 1;
            reper(i,N-K,N){
                (ans *= M[i]) %= MOD;
            }
            cout << (ans+MOD)%MOD << endl;
        }
        return 0;
    }

    vl Mp(mn / 2 + 1);
    vc<ld> mcnt(mn / 2 + 1);
    Mp[0] = 1;
    rep(i, mn/2){
        ll tmp = M[i * 2] * M[i * 2 + 1];
        mcnt[i + 1] = mcnt[i] + log((ld)tmp);

        tmp %= MOD;
        Mp[i + 1] = (Mp[i] * tmp) % MOD;

    }

    ll rk = K, ans = 0, acnt = 0;
    if (K % 2 == 0 and K <= mn) ans = Mp[mn / 2], acnt = mcnt[mn / 2];

    reverse(all(P));
    ll v = 1;
    ld vcnt = 0;

    rep(i, pn){
        if (rk == 0) break;
        v *= P[i];
        v %= MOD;
        vcnt += log((ld)P[i]);

        rk--;
        if(rk%2==0 and rk<=mn){
            ll tmp = v * Mp[rk / 2] % MOD;
            ld tcnt = vcnt + mcnt[rk / 2];

            if(tcnt>acnt){
                ans = tmp;
                acnt = tcnt;
            }
        }
        
    }

    verr(Mp, mn / 2 + 1);
    verr(mcnt, mn / 2 + 1);
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:121:5: error: 'verr' was not declared in this scope
  121 |     verr(Mp, mn / 2 + 1);
      |     ^~~~