Language: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll a[maxn];
int main() {
	int n,k;
	cin>>n>>k;
	int flag = 0;
	vector<pair<int,int>> v;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]>=0){
			if(a[i]==0) flag = 1;
			v.push_back({a[i],1});
		}else {
			v.push_back({-a[i],-1});
		}
	}
	sort(v.rbegin(),v.rend());
	vector<int> pos,neg;
	for(int i=0;i<v.size();i++){
		if(v[i].second==1){
			pos.push_back(i);
		}else {
			neg.push_back(i);
		}
	}
	if(k%2==1){
		if(pos.size()==0){
			int cnt = 0; 
			ll ans =1;
			for(int i=neg.size()-1;i>=0;i--){
				ans*=v[neg[i]].first*-1;
				cnt++;
				ans%=mod;
				if(cnt==k){
					break;
				}
			}
			if(flag){
				cout<<0<<endl;
			}else {
				cout<<(ans+mod)%mod<<endl;
			}
			
		}else {
			int cnt = 1;
			for(int i=1;i<pos.size()-1;i+=2){
				if(pos[i]<k&&pos[i+1]<k){
					cnt+=2;
				}
			}
			k-=cnt;
			if(cnt+1>=pos.size()||(k>=2&&cnt+1<=pos.size()&&[neg[k-2]].first*v[neg[k-1]].first>v[pos[cnt]].first*v[pos[cnt+1]].first)){
				ll ans = 1;
				for(int i=0;i<k;i++){
					ans*=v[neg[i]].first;
					ans%=mod;
				}
				for(int i=0;i<cnt;i++){
					ans*=v[pos[i]].first;
					ans%=mod;
				}
				cout<<(ans+mod)%mod<<endl;
			}else {
				ll ans = 1;
				if(k>=2){
					for(int i=0;i<k-2;i++){
					ans*=v[neg[i]].first;
					ans%=mod;
				}
				for(int i=0;i<cnt+2;i++){
					ans*=v[pos[i]].first;
					ans%=mod;
				}
				}else {
					for(int i=0;i<cnt;i++){
					ans*=v[pos[i]].first;
					ans%=mod;
				}
				}
				
				cout<<(ans+mod)%mod<<endl;
			}
		}
	}else {
		int cnt = 0;
			for(int i=0;i<pos.size()-1;i+=2){
				if(pos[i]<k&&pos[i+1]<k){
					cnt+=2;
				}
			}
			k-=cnt;
			if(cnt+1>=pos.size()||(k>=2&&cnt+1<=pos.size()&&[neg[k-2]].first*v[neg[k-1]].first>v[pos[cnt]].first*v[pos[cnt+1]].first)){
				ll ans = 1;
				for(int i=0;i<k;i++){
					ans*=v[neg[i]].first;
					ans%=mod;
				}
				for(int i=0;i<cnt;i++){
					ans*=v[pos[i]].first;
					ans%=mod;
				}
				cout<<(ans+mod)%mod<<endl;
			}else {
				ll ans = 0;
				if(k>=2){
					for(int i=0;i<k-2;i++){
					ans*=v[neg[i]].first;
					ans%=mod;
				}
				for(int i=0;i<cnt+2;i++){
					ans*=v[pos[i]].first;
					ans%=mod;
				}
				}else {
					for(int i=0;i<cnt;i++){
					ans*=v[pos[i]].first;
					ans%=mod;
				}
				}
				
				cout<<(ans+mod)%mod<<endl;
			}
	}
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:73:77: error: expected ',' before '[' token
   73 |                         if(cnt+1>=pos.size()||(k>=2&&cnt+1<=pos.size()&&[neg[k-2]].first*v[neg[k-1]].first>v[pos[cnt]].first*v[pos[cnt+1]].first)){
      |                                                                             ^
      |                                                                             ,
a.cc:73:77: error: expected identifier before '[' token
a.cc: In lambda function:
a.cc:73:83: error: expected '{' before '.' token
   73 |                         if(cnt+1>=pos.size()||(k>=2&&cnt+1<=pos.size()&&[neg[k-2]].first*v[neg[k-1]].first>v[pos[cnt]].first*v[pos[cnt+1]].first)){
      |                                                                                   ^
a.cc: In function 'int main()':
a.cc:73:84: error: 'struct main()::<lambda()>' has no member named 'first'
   73 |                         if(cnt+1>=pos.size()||(k>=2&&cnt+1<=pos.size()&&[neg[k-2]].first*v[neg[k-1]].first>v[pos[cnt]].first*v[pos[cnt+1]].first)){
      |                                                                                    ^~~~~
a.cc:113:77: error: expected ',' before '[' token
  113 |                         if(cnt+1>=pos.size()||(k>=2&&cnt+1<=pos.size()&&[neg[k-2]].first*v[neg[k-1]].first>v[pos[cnt]].first*v[pos[cnt+1]].first)){
      |                                                                             ^
      |                                                                             ,
a.cc:113:77: error: expected identifier before '[' token
a.cc: In lambda function:
a.cc:113:83: error: expected '{' before '.' token
  113 |                         if(cnt+1>=pos.size()||(k>=2&&cnt+1<=pos.size()&&[neg[k-2]].first*v[neg[k-1]].first>v[pos[cnt]].first*v[pos[cnt+1]].first)){
      |                                                                                   ^
a.cc: In function 'int main()':
a.cc:113:84: error: 'struct main()::<lambda()>' has no member named 'first'
  113 |                         if(cnt+1>=pos.size()||(k>=2&&cnt+1<=pos.size()&&[neg[k-2]].first*v[neg[k-1]].first>v[pos[cnt]].first*v[pos[cnt+1]].first)){
      |                                                                                    ^~~~~