Language: C++

#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define F first
#define S second
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define N 200010
using namespace std;
vector<ll> v1,v2,v3;
ll m=1e9+7;
void done(int i,int j)
{
    ll ans=1;
    for(int p=0;p<i;p++)
    {
        ans*=-1;
        ans*=v2[p];
        ans%=m;
        ans+=m;
        ans%=m;
       // cout<<ans<<endl;
    }


        for(int p=0;p<j;p++)
        ans=(ans*v3[p])%m;
    cout<<ans<<endl;
}
void done1(int i,int j)
{
    //cout<<"here ";
    ll ans=1;
    sort(all(v2));
    for(int p=0;p<i;p++)
    {
        ans*=-1;
        ans*=v2[p];
        ans+=m;
        ans%=m;
        //cout<<ans<<endl;
    }
    for(int p=0;p<j;p++)
        ans=(ans*v3[p])%m;
    cout<<ans<<endl;
}
void solve()
{
    ll n,k; cin>>n>>k;
    v1.clear(); v2.clear(); v3.clear();
    rep(i,0,n)
    {
        ll tmp; cin>>tmp;
        if(!tmp)v1.pb(tmp);
        if(tmp<0)v2.pb(-tmp);
        if(tmp>0)v3.pb(tmp);
    }
    if(n==k)
    {
        ll ans=1;
        for(auto j:v2)
            ans=(ans*(-j)+m)%m;
        for(auto j:v3)
            ans=(ans*j)%m;
        for(auto j:v1)
            ans=0;
        cout<<ans;
        return;
    }
    ll a=v1.size(),b=v2.size(),c=v3.size();
    if( (b+c<k) || ((b%2==1) && (b+c==k))
    {
        cout<<0<<endl; return;
    }
    if(v2.size()==0)
    {
        done(0,k); return;
    }
    if(v3.size()==0)
    {
        done1(k,0); return;
    }
    int p=v2.size(); int q=v3.size();
    sort(allr(v2));
    sort(allr(v3));
    int i=0,j=0;
    while(k--)
    {
        if(i==p)
            j++;
        else if(j==q)
            i++;
        else
        {
            if(v3[j]>=v2[i])
                j++;
            else
                i++;
        }
    }
    //cout<<"Here "<<i<<" "<<j<<endl;
    if(i%2==0)
    {
        done(i,j); return;
    }
    if(i==p)
        done(i-1,j+1);
    else if(j==q)
        done(i+1,j-1);
    else
    {
        if(v2[i]>=v3[j])
            done(i+1,j-1);
        else
            done(i-1,j+1);
    }
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int t=1;
  //cin>>t;
  //freopen("b2.in", "r", stdin);
  //freopen("output2.txt", "w", stdout);
  for(int i=1;i<=t;i++)
  {
      solve();
  }
  return 0;
}



Compiler output:
a.cc: In function 'void solve()':
a.cc:73:42: error: expected ';' before '{' token
   73 |     if( (b+c<k) || ((b%2==1) && (b+c==k))
      |                                          ^
      |                                          ;
   74 |     {
      |     ~                                     
a.cc:77:5: error: expected primary-expression before 'if'
   77 |     if(v2.size()==0)
      |     ^~
a.cc:76:6: error: expected ')' before 'if'
   76 |     }
      |      ^
      |      )
   77 |     if(v2.size()==0)
      |     ~~
a.cc:73:7: note: to match this '('
   73 |     if( (b+c<k) || ((b%2==1) && (b+c==k))
      |       ^
a.cc:91:15: error: 'p' was not declared in this scope
   91 |         if(i==p)
      |               ^
a.cc:108:11: error: 'p' was not declared in this scope
  108 |     if(i==p)
      |           ^