Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)
#define mul_mod(multiplicand, multiplier, mod) ((multiplicand*multiplie) % mod)

void mul1(ll *product, ll *idx, ll a, ll *taken){
    ll mod = 1e9 + 7;
    *product = mul_mod(*product, a, mod);
    *idx -= 1;
    *taken += 1;
}

void mul2(ll *product,ll *idx,ll a,ll b,ll *taken){
    ll mod = 1e9 + 7;
    *product = mul_mod(*product, a*b, mod);
    *idx -= 2;
    *taken += 2;
}

int main(){
    ll n,k;
    ll mod = 1e9 + 7;
    cin >> n >> k;
    vector<ll> pos;
    vector<ll> neg;
    ll cnt_zero = 0;
    ll maxa = -mod;
    rep1(i,n){
        ll tmp;
        cin >> tmp;
        maxa = max(maxa,tmp);
        if(tmp == 0){
            cnt_zero++;
            continue;
        }
        if(tmp > 0) pos.push_back(tmp);
        else neg.push_back(abs(tmp));
    }
    int pos_len = pos.size();
    int neg_len = neg.size();
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    ll product = 1;

    //obvious case
    if(k == 1){
        cout << (maxa+mod) % mod << endl;
        return 0;
    }
    if(cnt_zero == n){
        cout << 0 << endl;
        return 0;
    }
    if(n == k){
        if(cnt_zero > 0){
            product = 0;
        }else{
            rep0(i, pos_len-1) product = mul_mod(product,pos[i],mod);
            rep0(i, neg_len-1) product = mul_mod(product,neg[i],mod);    
        }
        cout << product << endl;
        return 0;
    }else{
        if(neg_len == 0){ //only 0 or positive
            rep1(i,cnt_zero) pos.insert(pos.begin(),0);
            pos_len += cnt_zero;
            for(int i = pos_len - 1;i >= pos_len - k;i--){
                product = mul_mod(product,pos[i],mod);
            }
            cout << product << endl;
            return 0;
        }else if(pos_len == 0){  //only 0 or negative
            if(cnt_zero == 0){
                if(k % 2 == 0){
                    for(int i = neg_len - 1;i >= neg_len - k;i--){
                        product = mul_mod(product,neg[i],mod);
                    }
                }else{
                    rep0(i,k-1) product = mul_mod(product,neg[i],mod);
                    product = (-product + mod) % mod;
                }
            }else{
                rep1(i,cnt_zero) neg.insert(neg.begin(),0);
                neg_len += cnt_zero;
                if(k % 2 == 0){
                    for(int i = neg_len - 1;i >= neg_len - k;i--){
                        product = mul_mod(product,neg[i],mod);
                    }
                }else{
                    product = 0;
                }
            }
            cout << product << endl;
            return 0;
        }
    }
    if( pos_len + neg_len < k){
        cout << 0 << endl;
        return 0;
    }

    //not obvious case
    rep1(i,cnt_zero) pos.insert(pos.begin(),0);
    pos_len += cnt_zero;
    ll pos_idx = pos_len - 1;
    ll neg_idx = neg_len - 1;
    ll taken = 0;
    while(taken < k){
        if(taken == 0 && (k % 2 == 1)){
            mul1(&product, &pos_idx, pos[pos_idx], &taken);
            continue;
        }
        if(pos_idx < 0){
            mul2(&product, &neg_idx, neg[neg_idx],neg[neg_idx-1], &taken);
        }else if(neg_idx <= 0){
            mul2(&product, &pos_idx, pos[pos_idx], pos[pos_idx-1],&taken);
        }else{
            if(pos_idx == 0){
                mul2(&product, &neg_idx, neg[neg_idx],neg[neg_idx-1], &taken);
            }else{
                ll pos_product = pos[pos_idx]*pos[pos_idx-1];
                ll neg_product = neg[neg_idx]*neg[neg_idx-1];
                if(pos_product > neg_product){
                    mul2(&product, &pos_idx, pos[pos_idx],pos[pos_idx-1], &taken);
                }else{
                    mul2(&product, &neg_idx, neg[neg_idx],neg[neg_idx-1], &taken);
                }
            }
        }    
    }
    cout << product << endl;
    return 0;
}

/*
5 3
-3 -2 -2 3 4
5 3
0 0 0 0 0
*/

Compiler output:
a.cc: In function 'void mul1(ll*, ll*, ll, ll*)':
a.cc:17:63: error: 'multiplie' was not declared in this scope
   17 | #define mul_mod(multiplicand, multiplier, mod) ((multiplicand*multiplie) % mod)
      |                                                               ^~~~~~~~~
a.cc:21:16: note: in expansion of macro 'mul_mod'
   21 |     *product = mul_mod(*product, a, mod);
      |                ^~~~~~~
a.cc: In function 'void mul2(ll*, ll*, ll, ll, ll*)':
a.cc:17:63: error: 'multiplie' was not declared in this scope
   17 | #define mul_mod(multiplicand, multiplier, mod) ((multiplicand*multiplie) % mod)
      |                                                               ^~~~~~~~~
a.cc:28:16: note: in expansion of macro 'mul_mod'
   28 |     *product = mul_mod(*product, a*b, mod);
      |                ^~~~~~~
a.cc: In function 'int main()':
a.cc:17:63: error: 'multiplie' was not declared in this scope
   17 | #define mul_mod(multiplicand, multiplier, mod) ((multiplicand*multiplie) % mod)
      |                                                               ^~~~~~~~~
a.cc:71:42: note: in expansion of macro 'mul_mod'
   71 |             rep0(i, pos_len-1) product = mul_mod(product,pos[i],mod);
      |                                          ^~~~~~~
a.cc:17:63: error: 'multiplie' was not declared in this scope
   17 | #define mul_mod(multiplicand, multiplier, mod) ((multiplicand*multiplie) % mod)
      |                                                               ^~~~~~~~~
a.cc:72:42: note: in expansion of macro 'mul_mod'
   72 |             rep0(i, neg_len-1) product = mul_mod(product,neg[i],mod);
      |                                          ^~~~~~~
a.cc:17:63: error: 'multiplie' was not declared in this scope
   17 | #define mul_mod(multiplicand, multiplier, mod) ((multiplicand*multiplie) % mod)
      |                                                               ^~~~~~~~~
a.cc:81:27: note: in expansion of macro 'mul_mod'
   81 |                 product = mul_mod(product,pos[i],mod);
      |                           ^~~~~~~
a.cc:17:63: error: 'multiplie' was not declared in this scope
   17 | #define mul_mod(multiplicand, multiplier, mod) ((multiplicand*multiplie) % mod)
      |                                                               ^~~~~~~~~
a.cc:89:35: note: in expansion of macro 'mul_mod'
   89 |                         product = mul_mod(product,neg[i],mod);
      |                                   ^~~~~~~
a.cc:17:63: error: 'multiplie' was not declared in this scope
   17 | #define mul_mod(multiplicand, multiplier, mod) ((multiplicand*multiplie) % mod)
      |                                                               ^~~~~~~~~
a.cc:92:43: note: in expansion of macro 'mul_mod'
   92 |                     rep0(i,k-1) product = mul_mod(product,neg[i],mod);
      |                                           ^~~~~~~
a.cc:17:63: error: 'multiplie' was not declared in this scope
   17 | #define mul_mod(multiplicand, multiplier, mod) ((multiplicand*multiplie) % mod)
      |                                                               ^~~~~~~~~
a.cc:100:35: note: in expansion of macro 'mul_mod'
  100 |                         product = mul_mod(product,neg[i],mod);
      |                                   ^~~~~~~