Language: C++

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::sort(all(a));
	int l=0,r=n;
	rep(i,k) {
		if(std::abs(a[l])>std::abs(a[r-1])) l++;
		else r--;
	}
	if(l%2==0||l==r) {
		mint ans=1;
		rep(i,l) ans*=a[i];
		for(int i=r;i<n;i++) ans*=a[i];
		print(ans);
		return 0;
	}
	mint ans=1;
	if(l==0||std::abs(a[l]*a[l-1])>=std::abs(a[r-1]*a[r])) {
		rep(i,l+1) ans*=a[i];
		for(int i=r+1;i<n;i++) ans*=a[i];
	} else {
		rep(i,l-1) ans*=a[i];
		for(int i=r-1;i<n;i++) ans*=a[i];
	}
	print(ans);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:46:17: error: 'mint' was not declared in this scope; did you mean 'uint'?
   46 |                 mint ans=1;
      |                 ^~~~
      |                 uint
a.cc:47:26: error: 'ans' was not declared in this scope; did you mean 'abs'?
   47 |                 rep(i,l) ans*=a[i];
      |                          ^~~
      |                          abs
a.cc:48:38: error: 'ans' was not declared in this scope; did you mean 'abs'?
   48 |                 for(int i=r;i<n;i++) ans*=a[i];
      |                                      ^~~
      |                                      abs
a.cc:49:23: error: 'ans' was not declared in this scope; did you mean 'abs'?
   49 |                 print(ans);
      |                       ^~~
a.cc:28:32: note: in definition of macro 'print'
   28 | #define print(i) std::cout << (i) << '\n'
      |                                ^
a.cc:52:9: error: 'mint' was not declared in this scope; did you mean 'uint'?
   52 |         mint ans=1;
      |         ^~~~
      |         uint
a.cc:54:28: error: 'ans' was not declared in this scope; did you mean 'abs'?
   54 |                 rep(i,l+1) ans*=a[i];
      |                            ^~~
      |                            abs
a.cc:55:40: error: 'ans' was not declared in this scope; did you mean 'abs'?
   55 |                 for(int i=r+1;i<n;i++) ans*=a[i];
      |                                        ^~~
      |                                        abs
a.cc:57:28: error: 'ans' was not declared in this scope; did you mean 'abs'?
   57 |                 rep(i,l-1) ans*=a[i];
      |                            ^~~
      |                            abs
a.cc:58:40: error: 'ans' was not declared in this scope; did you mean 'abs'?
   58 |                 for(int i=r-1;i<n;i++) ans*=a[i];
      |                                        ^~~
      |                                        abs
a.cc:60:15: error: 'ans' was not declared in this scope; did you mean 'abs'?
   60 |         print(ans);
      |               ^~~
a.cc:28:32: note: in definition of macro 'print'
   28 | #define print(i) std::cout << (i) << '\n'
      |                                ^