Language: C++

#include <iostream>
using namespace std;

long long int K, A[100000], max_a = 0, min_a = 0, max = 0, min = 1000000000, ma;

void max_(long long int m, int sum)
{
	//cout << m << " : " << sum << endl;

	if (m == 0)sum = K;

	if (sum == K) {
		if (max_a < m) {
			return;
		}
		if (max < ma && m == 2)max = ma;
		if (min > ma && m == 2)min = ma;
		ma++;
		max_(ma, 0);
		return;
	}

	max_(m - m%A[sum], sum + 1);
}

int main()
{
	cin >> K;

	for (int i = 0; i < K; i++) {
		scanf("%d", &A[i]);
		if (A[i] > min_a)min_a = A[i];
	}

	max_a = A[K - 1] * 2 + 1;

	ma = min_a;
	max_(min_a, 0);

	if (max > 0 && min > 0)
		cout << min << " " << max << endl;
	else cout << -1 << endl;

	return 0;
}

Compiler output:
a.cc: In function 'void max_(long long int, int)':
a.cc:16:21: error: reference to 'max' is ambiguous
   16 |                 if (max < ma && m == 2)max = ma;
      |                     ^~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:51: note:                 'long long int max'
    4 | long long int K, A[100000], max_a = 0, min_a = 0, max = 0, min = 1000000000, ma;
      |                                                   ^~~
a.cc:16:40: error: reference to 'max' is ambiguous
   16 |                 if (max < ma && m == 2)max = ma;
      |                                        ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:51: note:                 'long long int max'
    4 | long long int K, A[100000], max_a = 0, min_a = 0, max = 0, min = 1000000000, ma;
      |                                                   ^~~
a.cc:17:21: error: reference to 'min' is ambiguous
   17 |                 if (min > ma && m == 2)min = ma;
      |                     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:60: note:                 'long long int min'
    4 | long long int K, A[100000], max_a = 0, min_a = 0, max = 0, min = 1000000000, ma;
      |                                                            ^~~
a.cc:17:40: error: reference to 'min' is ambiguous
   17 |                 if (min > ma && m == 2)min = ma;
      |                                        ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:60: note:                 'long long int min'
    4 | long long int K, A[100000], max_a = 0, min_a = 0, max = 0, min = 1000000000, ma;
      |                                                            ^~~
a.cc: In function 'int main()':
a.cc:40:13: error: reference to 'max' is ambiguous
   40 |         if (max > 0 && min > 0)
      |             ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:51: note:                 'long long int max'
    4 | long long int K, A[100000], max_a = 0, min_a = 0, max = 0, min = 1000000000, ma;
      |                                                   ^~~
a.cc:40:24: error: reference to 'min' is ambiguous
   40 |         if (max > 0 && min > 0)
      |                        ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:60: note:                 'long long int min'
    4 | long long int K, A[100000], max_a = 0, min_a = 0, max = 0, min = 1000000000, ma;
      |                                                            ^~~
a.cc:41:25: error: reference to 'min' is ambiguous
   41 |                 cout << min << " " << max << endl;
      |                         ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:60: note:                 'long long int min'
    4 | long long int K, A[100000], max_a = 0, min_a = 0, max = 0, min = 1000000000, ma;
      |                                                            ^~~
a.cc:41:39: error: reference to 'max' is ambiguous
   41 |                 cout << min << " " << max << endl;
      |                                       ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:51: note:                 'long long int max'
    4 | long long int K, A[100000], max_a = 0, min_a = 0, max = 0, min = 1000000000, ma;
      |                                                   ^~~