/*#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
template<class T>
inline void read(T& a){
T x = 0, f = 1; char c = getchar();
while(!isdigit(c)){if(c == '-') f = -1; c = getchar();}
while(isdigit(c)){x = x * 10 + c - '0'; c = getchar();}
a = x * f;
}
int n, a[maxn], aa[maxn], cnt;
int main(){
read(n);
for(register int i = 0; i < n; ++i) read(a[i]);
for(register int i = 0; i < n; ++i)
for(register int j = 0; j < n; ++j)
if(i != j)
aa[++cnt] = a[i] % a[j];
memset(a, false, sizeof(a));
sort(aa + 1, aa + cnt + 1);
int tmp = unique(aa + 1, aa + cnt + 1) - aa - 1;
printf("%d\n", aa[tmp - 1]);
return 0;
}*/
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
template<class T>
inline void read(T& a){
T x = 0, f = 1; char c = getchar();
while(!isdigit(c)){if(c == '-') f = -1; c = getchar();}
while(isdigit(c)){x = x * 10 + c - '0'; c = getchar();}
a = x * f;
}
int n, a[maxn];
int main(){
read(n);
for(register int i = 1; i <= n; ++i) read(a[i]);
sort(a + 1, a + n + 1);
a[0] = 0;
n = unique(a + 1, a + n + 1) - a - 1;
if(n <= 1) return puts("-1"), false;
else return printf("%d\n", max(a[n - 2], a[n] % a[n - 1])), false;
}
次大值怎么求???
最新推荐文章于 2024-04-20 22:36:21 发布