Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}



int main(){
    int n,k;cin>>n>>k;
	vi a;
	vi b;
	vll p;
rep(i,n){
	int an;
	cin>>an;
	if(an<0)b.pb(an);
	else a.pb(an);
}	
sort(all(a));
sort(all(b));
mint ans=1;
if(a.size()==0){
	if(k%2==0)rep(i,k)ans*=b.at(i);
	else rep(i,k)ans*=b.back(i);
	cout<<ans<<endl;
	return 0;	
	}else{
	reverse(all(b));
	while(b.size()>=2){
	ll x=b.back();b.popb();
	x*=b.back();b.popb();
	p.pb(x);
	}
	if(k%2==0){
	while(a.size()>=2){
	ll x=a.back();a.popb();
	x*=a.back();a.popb();
	p.pb(x);
	}
	sort(all(p));
	rep(i,k/2)ans*=p.back(i);	
	cout<<ans<<endl;
	return 0;
	}else{
	p.pb(a.back());
	a.popb();
	while(a.size()>=2){
	ll x=a.back();a.popb();
	x*=a.back();a.popb();
	p.pb(x);
	}
	sort(all(p));
	rep(i,k/2)ans*=p.back(i);	
	cout<<ans<<endl;
	return 0;
	
	}
	
	}


	
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:85:33: error: no matching function for call to 'std::vector<int>::back(int&)'
   85 |         else rep(i,k)ans*=b.back(i);
      |                           ~~~~~~^~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:1235:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::back() [with _Tp = int; _Alloc = std::allocator<int>; reference = int&]'
 1235 |       back() _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_vector.h:1235:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:1247:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::back() const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&]'
 1247 |       back() const _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_vector.h:1247:7: note:   candidate expects 0 arguments, 1 provided
a.cc:102:30: error: no matching function for call to 'std::vector<long long int>::back(int&)'
  102 |         rep(i,k/2)ans*=p.back(i);
      |                        ~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1235:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::back() [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&]'
 1235 |       back() _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_vector.h:1235:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:1247:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::back() const [with _Tp = long long int; _Alloc = std::allocator<long long int>; const_reference = const long long int&]'
 1247 |       back() const _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_vector.h:1247:7: note:   candidate expects 0 arguments, 1 provided
a.cc:114:30: error: no matching function for call to 'std::vector<long long int>::back(int&)'
  114 |         rep(i,k/2)ans*=p.back(i);
      |                        ~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1235:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::back() [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&]'
 1235 |       back() _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_vector.h:1235:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:1247:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::back() const [with _Tp = long long int; _Alloc = std::allocator<long long int>; const_reference = const long long int&]'
 1247 |       back() const _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_vector.h:1247:7: note:   candidate expects 0 arguments, 1 provided