Language: C++

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bits/stdc++.h>
using namespace std;
int ok=0;
bool cmp(long long a,long long b) {
	return a>b;
}
long long lt[100551]= {0};
long long at[100551]= {0};
int main() {
	long long k,ans=2,maxx,minn,z,zz,zzz,x=0;
	scanf("%lld",&k);
	for(int i=0; i<k; i++) {
		scanf("%lld",&lt[i]);
		at[i]=lt[i];
	}
	if(lt[k-1]>2) {
		puts("-1");
		return 0;
	}
	for(int i=k-1; i>=0; i--) {
		z=ceil((double)ans/lt[i])*lt[i];
		//	zz=ceil((double)ans/lt[i]+1)*lt[i];
		//	zzz=ceil((double)ans/lt[i]-1)*lt[i];
		if(z<=2*ans-1&&z>=ans)ans=z;
		else {
			puts("-1");
			return 0;
		}
	}
	minn=ans;
	ans=2;
	long b=0;
	for(int i=k-1; i>=0; i--) {
		b=ans;
		z=ceil((double)ans/lt[i])*lt[i];
		zz=ceil((double)ans/lt[i]+1)*lt[i];
		zzz=ceil((double)ans/lt[i]-1)*lt[i];
		if(z<=2*ans-1&&z>=ans) {
			ok=1;
			b=max(z,b);
		}
		if(zz<=2*ans-1&&zz>=ans) {
			ok=1;
			b=max(zz,b);
		}
		if(zzz<=2*ans-1&&zzz>=ans) {
			ok=1;
			b=max(zzz,b);
		}
		ans=b;
		if(ok==0) {
			puts("-1");
			return 0;
		}
		ok=0;
	}
	cout<<minn<<' '<<ans+lt[0]-1<<endl;
	return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:30: error: no matching function for call to 'max(long long int&, long int&)'
   52 |                         b=max(z,b);
      |                           ~~~^~~~~
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: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:52:30: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   52 |                         b=max(z,b);
      |                           ~~~^~~~~
/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,
                 from a.cc:6:
/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:52:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   52 |                         b=max(z,b);
      |                           ~~~^~~~~
a.cc:56:30: error: no matching function for call to 'max(long long int&, long int&)'
   56 |                         b=max(zz,b);
      |                           ~~~^~~~~~
/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:56:30: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   56 |                         b=max(zz,b);
      |                           ~~~^~~~~~
/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:56:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   56 |                         b=max(zz,b);
      |                           ~~~^~~~~~
a.cc:60:30: error: no matching function for call to 'max(long long int&, long int&)'
   60 |                         b=max(zzz,b);
      |                           ~~~^~~~~~~
/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:60:30: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   60 |                         b=max(zzz,b);
      |                           ~~~^~~~~~~
/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:60:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   60 |                         b=max(zzz,b);
      |                           ~~~^~~~~~~