Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

ll MOD = 1e9 + 7;

ll f(int pi, int mi, vector<ll> p, vector<ll> m) {
    ll ans = 1;
    rep(i, pi) {
        ans = (ans * p[p.size() - 1 - i]) % MOD;
    }
    rep(i, mi) {
        ans = (ans * (MOD - m[m.size() - 1 - i])) % MOD;
    }
    return ans;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N), p, m;
    vector<pair<ll, ll>> B(N);
    rep(i, N) {
        cin >> A[i];
        B[i] = make_pair(abs(A[i]), A[i]);
        if (A[i] >= 0) p.push_back(A[i]);
        else m.push_back(-A[i]);
    }
    sort(B.begin(), B.end());
    sort(p.begin(), p.end());
    sort(m.begin(), m.end());
    if (K % 2 == 1 && p.size() == 0) {
        ll ans = 1;
        rep(i, K) {
            ans = (ans * (MOD - m[i])) % MOD;
        }
        cout << ans << "\n";
        return 0;
    }
    int mi = min(K / 2 * 2, m.size() / 2 * 2);
    int pi = K - mi;
    for (int i = mi - 2; i >= 0; i -= 2) {
        ll mx = m[m.size() - i - 1] * m[m.size() - i - 2];
        ll px = p[p.size() - pi - 1] * p[p.size() - pi - 2];
        if (px > mx) {
            cout << f(K - i, i, p, m) << "\n";
            return 0;
        }
    }
    cout << f(K, 0, p, m) << "\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:17: error: no matching function for call to 'min(int, std::vector<long long int>::size_type)'
   42 |     int mi = min(K / 2 * 2, m.size() / 2 * 2);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:   template argument deduction/substitution failed:
a.cc:42:17: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'})
   42 |     int mi = min(K / 2 * 2, m.size() / 2 * 2);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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, 2 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:   candidate expects 1 argument, 2 provided
/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:   template argument deduction/substitution failed:
a.cc:42:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   42 |     int mi = min(K / 2 * 2, m.size() / 2 * 2);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~