Language: C++

#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
 
using namespace std;
typedef long long ll;
ll n, k;
ll ans = 1;
ll l_neg = -1, l_pos = -1, r_neg = -1, r_pos = -1;
const ll M = 1e9+7;
 
bool cmp(ll a, ll b)
{
	return abs(a) < abs(b);
}
 
ll calc(vector<ll> a)
{
	ll temp = 1;
	for(ll i = n - k; i < n; i++)
		temp = (temp * a[i]) % M;
	return temp;
}
 
bool v_cmp(vector<ll> a, vector<ll> b)
{
	ll sum1 = 0, sum2 = 0;
	for(ll i = n - k; i < n; i++){
		sum1 += abs(a[i]);
		sum2 += abs(b[i]);
	}
	return sum1 > sum2;
}
 
int main() {
	cin >> n >> k;
	vector<ll> a(n, 0);
	for(ll i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end(), cmp);
 
	for(ll i = n - k; i < n; i++){
		ans = (ans * a[i]) % M;
		if(r_pos == -1 && a[i] > 0) r_pos = i;
		if(r_neg == -1 && a[i] < 0) r_neg = i;
	}
	for(ll i = n - k - 1; i >= 0; i--){
		if(l_pos == -1 && a[i] > 0) l_pos = i;
		if(l_neg == -1 && a[i] < 0) l_neg = i;
	}
	
	if(ans < 0 && n != k){
		if(r_pos == -1){
			if(l_pos == -1){
				ans = 1;
				for(int i = 0; i < k; i++)
					ans = (ans * a[i]) % M;
			}
			else {
				swap(a[l_pos], a[r_neg]);
				ans = calc(a);
			}
		}
		else {
			if(l_neg == -1){
				swap(a[l_pos], a[r_neg]);
				ans = calc(a);
			}
			else if(l_pos == -1){
				swap(a[l_neg], a[r_pos]);
				ans = calc(a);
			}
			else {
				vector<int> c1 = a;
				vector<int> c2 = a;
				swap(c1[l_neg], c1[r_pos]);
				swap(c2[l_pos], c2[r_neg]);
				ans = v_cmp(c1, c2) == true? calc(c1): calc(c2);
			}
		}
	}
	if(ans<0)
	ans=ans+M;
	cout << ans << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:75:50: error: conversion from 'vector<long long int>' to non-scalar type 'vector<int>' requested
   75 |                                 vector<int> c1 = a;
      |                                                  ^
a.cc:76:50: error: conversion from 'vector<long long int>' to non-scalar type 'vector<int>' requested
   76 |                                 vector<int> c2 = a;
      |                                                  ^
a.cc:79:45: error: could not convert 'c1' from 'vector<int>' to 'vector<long long int>'
   79 |                                 ans = v_cmp(c1, c2) == true? calc(c1): calc(c2);
      |                                             ^~
      |                                             |
      |                                             vector<int>
a.cc:79:67: error: could not convert 'c1' from 'vector<int>' to 'vector<long long int>'
   79 |                                 ans = v_cmp(c1, c2) == true? calc(c1): calc(c2);
      |                                                                   ^~
      |                                                                   |
      |                                                                   vector<int>
a.cc:79:77: error: could not convert 'c2' from 'vector<int>' to 'vector<long long int>'
   79 |                                 ans = v_cmp(c1, c2) == true? calc(c1): calc(c2);
      |                                                                             ^~
      |                                                                             |
      |                                                                             vector<int>