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){

		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;
			}
		}

		if (cnt_zero != 0LL){
			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-10000000000LL;
		if (cnt_zero != 0){
			res = 0LL;
		}
		ll border = min(k/2LL,ne_len/2LL);
		for(ll i = 0; i <= border; i++) {
			ll ans = 1LL;
			ans *= sum_ne[i * 2LL];
			// cout << ans << endl;
			ans %= mod;
			ll index_po = min(po_len,k - i * 2LL);
			ans *= sum_po[index_po];
			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:125:23: error: expected initializer before '-' token
  125 |                 ll res-10000000000LL;
      |                       ^
a.cc:127:25: error: 'res' was not declared in this scope
  127 |                         res = 0LL;
      |                         ^~~
a.cc:145:25: error: 'res' was not declared in this scope
  145 |                         res = max(res,ans);
      |                         ^~~
a.cc:147:25: error: 'res' was not declared in this scope
  147 |                 cout << res << endl;
      |                         ^~~