Language: C++

#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

int MOD = 1e9 + 7;

ll mod(ll a, ll b){ 
	return (a % b + b) % b; 
}

int main(){
	int n, k;
	cin >> n >> k;
	
	vector <int> d(n);
	for(int i = 0; i < n; i++)
		cin >> d[i];
		
	vector <__int128> p, m, mm;
	
	int zero = 0;
	
	for(int i = 0; i < n; i++)
		if(d[i] < 0){
			m.pb(d[i]);
			mm.pb(d[i]);
		}
		else if(d[i] > 0)
			p.pb(d[i]);
		else
			zero++;
		
	sort(all(p));
	reverse(all(p));
	sort(all(m));
	sort(all(mm));
	reverse(all(mm));
	
	for(int i = 1; i < len(p); i++)
		p[i] = mod((p[i] * p[i-1]), MOD);
	for(int i = 1; i < len(m); i++)
		m[i] = mod((m[i] * m[i-1]), MOD);
	for(int i = 1; i < len(mm); i++)
		mm[i] = mod((mm[i] * mm[i-1]), MOD);
		
	if(k > len(p) + len(m)){
		cout << 0 << endl;
		return 0;
	}
	
	p.insert(p.begin(), 1);
	m.insert(m.begin(), 1);
	mm.insert(mm.begin(), 1);

	__int128 mx = (zero > 0 ? 0 : -1e9);
	for(int i = 0; i < len(p); i++){
		int idx = k - i;
		
		if(idx < 0 || idx >= len(m))
			continue;
				
		if(idx % 2 == 0)
			mx = max(mx, mod((p[i] * m[idx]), MOD));
		else{
			mx = max(mx, mod((p[i] * mm[idx]), MOD));
		}
	}

	cout << mod(mx, MOD) << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:73:33: error: no matching function for call to 'max(__int128&, ll)'
   73 |                         mx = max(mx, mod((p[i] * m[idx]), MOD));
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:73:33: note:   deduced conflicting types for parameter 'const _Tp' ('__int128' and 'll' {aka 'long long int'})
   73 |                         mx = max(mx, mod((p[i] * m[idx]), MOD));
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:73:33: note:   mismatched types 'std::initializer_list<_Tp>' and '__int128'
   73 |                         mx = max(mx, mod((p[i] * m[idx]), MOD));
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:75:33: error: no matching function for call to 'max(__int128&, ll)'
   75 |                         mx = max(mx, mod((p[i] * mm[idx]), MOD));
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:75:33: note:   deduced conflicting types for parameter 'const _Tp' ('__int128' and 'll' {aka 'long long int'})
   75 |                         mx = max(mx, mod((p[i] * mm[idx]), MOD));
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:75:33: note:   mismatched types 'std::initializer_list<_Tp>' and '__int128'
   75 |                         mx = max(mx, mod((p[i] * mm[idx]), MOD));
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~