Language: C++

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	ll n,k;cin>>n>>k;
	vector<ll> po;
	vector<ll> ne;
	ll cnt_zero = 0;
	for(ll i = 0; i < n; i++) {
		ll x;cin>>x;
		if (x > 0){
			po.pb(x);
		}
		else if(x != 0){
			ne.pb(x);
		}
		else{
			cnt_zero++;
		}
	}
	ll po_len = po.size();
	ll ne_len = ne.size();

	

	k -= cnt_zero;
	

	// for(int i = 0; i < po_len; i++) {
	// 	cout << ne[i] << endl;
	// }
	


	if (k == po_len + ne_len){
		if (cnt_zero != 0){
			cout << 0 << endl;
		}
		else{
			if (po_len == 0){
				cout << sum_ne[ne_len] << endl;
			}
			else if (ne_len == 0){
				cout << sum_po[po_len] << endl;
			}
			else{
				cout << sum_po[po_len] * sum_ne[ne_len] % mod << endl;
			}
		}
		return 0;
	}
	
	else if (k % 2 == 1 && po_len == 0){
		ll res;
		sort(ALL(ne),greater<ll>());
		vector<ll> sum_ne(ne_len+1,1LL);
		for(ll i = 0; i < ne_len; i++) {
			sum_ne[i+1] = sum_ne[i] * ne[i];
			sum_ne[i+1] %= mod;
			if(sum_ne[i+1] < 0LL){
			sum_ne[i+1] += mod;
		}
		}
		if (cnt_zero != 0){
			res = max(0LL,sum_ne[k]);
		}
		else{
			res = sum_ne[k];
		}
		if(res < 0LL){
			res += mod;
		}
		cout << res << endl;
		return 0;
	}
	else{
		sort(ALL(po),greater<ll>());
		sort(ALL(ne));
		vector<ll> sum_po(po_len+1,1LL);
		vector<ll> sum_ne(ne_len+1,1LL);

		for(ll i = 0; i < po_len; i++) {
			sum_po[i+1] = sum_po[i] * po[i];
			sum_po[i+1] %= mod;
		}
		for(ll i = 0; i < ne_len; i++) {
			sum_ne[i+1] = sum_ne[i] * ne[i];
			sum_ne[i+1] %= mod;
			if(sum_ne[i+1] < 0LL){
				sum_ne[i+1] += mod;
			}
		}
		ll res;
		if (cnt_zero != 0){
			res = 0;
		}
		else {
			res = -1;
		}
		ll border = min(k,ne_len/2LL);
		for(ll i = 0; i <= border; i++) {
			ll ans = 1LL;
			ans *= sum_ne[i * 2LL];
			// cout << ans << endl;
			ans %= mod;
			ans *= sum_po[k - i * 2];
			ans %= mod;
			if (ans < 0LL){
				ans = mod;
			}
			// cout << "ans" << i << endl;
			if(cnt_zero != 0){
				ans = max(0LL,ans);
			}
			res = max(res,ans);
		}
		cout << res << endl;
	}




	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:41: error: 'sum_ne' was not declared in this scope
   55 |                                 cout << sum_ne[ne_len] << endl;
      |                                         ^~~~~~
a.cc:58:41: error: 'sum_po' was not declared in this scope
   58 |                                 cout << sum_po[po_len] << endl;
      |                                         ^~~~~~
a.cc:61:41: error: 'sum_po' was not declared in this scope
   61 |                                 cout << sum_po[po_len] * sum_ne[ne_len] % mod << endl;
      |                                         ^~~~~~
a.cc:61:58: error: 'sum_ne' was not declared in this scope
   61 |                                 cout << sum_po[po_len] * sum_ne[ne_len] % mod << endl;
      |                                                          ^~~~~~