Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;

const ll mod = 1e9+7;

ll fexp(ll a, ll b) {
  ll ans = 1;
  while(b) {
    if(b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}

void solve (){
	int n, k;
	cin >> n >> k;

	vector<ii> ent;

	int a;
	int zero = 0;
	for(int i = 0; i < n; i++){
		cin >> a;
		if(a == 0) {
			zero++;
		}
		if(a > 0) ent.push_back({a, 1});
		else ent.push_back({-a, -1});
	}
	
	sort(ent.begin(), ent.end(), greater<ii>());
	
	ll prod = 1;
	ll neg = -1;
	ll pos = -1;
	for(int i = 0; i < min(k); i++){
		prod *= ent[i].first;
		prod %= mod;
		if(ent[i].second < 0){
			if(neg == -1)
				neg = ent[i].first;
			else
				neg = -1;
		}
		else
			pos = ent[i].first;
	}
	
	if(neg == -1){
		cout << prod << endl;
		return;
	}
	
	int neg1 = -1, pos1 = -1;
	for(int i = k; i < n; i++){
		if(ent[i].second > 0){
			if(pos1 == -1){
				pos1 = ent[i].first;
			}
		}
		else{
			if(neg1 == -1){ 
				neg1 = ent[i].first;
			}
		}
	}
	
	if((pos1 == -1 || pos == -1) && neg1 == -1){
		if(zero)	
			cout << 0 << endl;
		else
			cout << (mod - prod) % mod << endl;
		return;
	}
	
	if(pos * pos1 < neg * neg1){
		ll inv = fexp(pos, mod-2);
		prod = prod * inv % mod;
		prod = (prod * neg1 + mod) % mod;
		cout << prod << endl;
		return;
	}
	
	ll inv = fexp(neg, mod-2);
	prod = prod * inv % mod;
	prod = (prod * pos1 + mod) % mod;
	cout << prod << endl;
}

int32_t main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	int tc = 1;
	//cin >> tc;
	while(tc--)
	
		solve();
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:42:31: error: no matching function for call to 'min(int&)'
   42 |         for(int i = 0; i < min(k); i++){
      |                            ~~~^~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
a.cc:42:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   42 |         for(int i = 0; i < min(k); i++){
      |                            ~~~^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided