Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pr pair<ll, ll>
#define vct vector<ll>
#define vpt vector<pr>
#define st set<ll>
#define pq priority_queue<ll>
#define mat vector<vector<ll> >
#define F(i, n) for (i = 0; i < (1LL*n); i++)
#define Fr(i, n) for (i = n - 1; i >= 0; i--)
struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<long long, int, custom_hash>
void prv(vct v)
{
    for (ll i = 0; i < v.size(); i++)
        cout << v[i] << " ";
    cout << "\n";
}
ll poww(ll x, ll y, ll m)
{
    ll res = 1;
    while (y)
    {
        if (y % 2 == 0)
        {
            x = (x * x) % m;
            y = y / 2;
        }
        else
        {
            res = (res * x) % m;
            y--;
        }
    }
    return res;
}
void deb(string s, ll n)
{
    cout << s << " : " << n << "\n";
}
void prn(ll n) { cout << n << "\n"; }
void prs(string n) { cout << n << "\n"; }
ll cntd(ll n){
    ll an=0;
    while(n){
        an+=(n%10);
        n/=10;
    }
    return an;
}
mat mt;
void setmtsize(ll m,ll n, ll ini=0){
    mt.resize(m,vector<ll>(n,ini));
}
void prmt(mat m){
    for(ll i=0;i<(1LL*m.size());i++)prv(m[i]);
}

ll n, k, m, l, r, x, y, ans=0;
ll t, t1, t2;

ll i, j;
ll a, b;
ll mod = 1000000007;


void solve()
{
    ans=0;
    cin>>n>>k;
    vct v(n);
    F(i,n)cin>>v[i];
    vct pos,neg,zz;
    F(i,n){
        if(v[i]<0)neg.pb(v[i]);
        else if(v[i]>0)pos.pb(v[i]);
        else zz.pb(v[i]);
    }
    // deb("pos size",pos.size());
    sort(pos.begin(),pos.end(),greater<ll>());
    sort(neg.begin(),neg.end());
    if((pos.size()+neg.size()) < k){
        prn(0);
        return;
    }
    else if(pos.size()+neg.size() == k){
        ans=1;
        F(i,pos.size())ans=(ans*pos[i])%mod;
        F(i,neg.size()){
            ans=(ans*neg[i])%mod;
            if(ans<0)ans+=mod;
        }
        prn(ans);
        return;
    }
    else if(pos.size()==0){
        ans=1;
        if((k%2)==1)reverse(neg.begin(),neg.end());
        F(i,k){
            ans=(ans*neg[i])%mod;
            if(ans<0)ans+=mod;
        }
        prn(ans);
        return;
    }
    ll ind=pos.size()-1;
    ll selpos=min(1LL*pos.size(),k);
    i=0;j=min(1LL*(pos.size()-1),k);
    ind=selpos-1;
    ll rm=k-selpos;
    ll alneg=0;
    if(rm){
        if(rm%2==0){
            i=rm;
        }
        else{
            // if(ind>=0){
                i=rm+1;
                ind--;
            
        }
    }
    // k-=pos.size();
    while(true){
        if(ind<=0 || i>=(neg.size()-1))break;
        if((i+1)<neg.size() && ((ind-1) >= 0)){
            ll mpos=pos[ind]*pos[ind-1];
            ll mneg=neg[i]*neg[i+1];
            if(mneg>mpos){
                ind-=2;
                i+=2;
            }
            else break;
        }
        else break;
    }

    ans=1;
    for(j=0;j<=ind;j++)ans=(ans*pos[j])%mod;
    for(j=0;j<i;j++){
        ans=(ans*neg[j])%mod;
        if(ans<0)ans+=mod;
    }
    prn(ans);
}

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


Compiler output:
a.cc: In function 'void solve()':
a.cc:124:18: error: no matching function for call to 'min(long long unsigned int, long long int&)'
  124 |     ll selpos=min(1LL*pos.size(),k);
      |               ~~~^~~~~~~~~~~~~~~~~~
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:124:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int')
  124 |     ll selpos=min(1LL*pos.size(),k);
      |               ~~~^~~~~~~~~~~~~~~~~~
/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:124:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
  124 |     ll selpos=min(1LL*pos.size(),k);
      |               ~~~^~~~~~~~~~~~~~~~~~
a.cc:125:14: error: no matching function for call to 'min(long long unsigned int, long long int&)'
  125 |     i=0;j=min(1LL*(pos.size()-1),k);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~
/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:125:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int')
  125 |     i=0;j=min(1LL*(pos.size()-1),k);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~
/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
/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:125:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
  125 |     i=0;j=min(1LL*(pos.size()-1),k);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~