25 lines
555 B
C++
25 lines
555 B
C++
|
#include <iostream>
|
||
|
#include <vector>
|
||
|
#include <algorithm>
|
||
|
using namespace std;
|
||
|
int main() {
|
||
|
int k;
|
||
|
cin >> k;
|
||
|
vector<int> arr;
|
||
|
for (int i = 0; i < k; i++) {
|
||
|
int t;
|
||
|
cin >> t;
|
||
|
arr.push_back(t);
|
||
|
}
|
||
|
auto ptr = unique(arr.begin(), arr.end());
|
||
|
arr.erase(ptr, arr.end());
|
||
|
if (arr.size() <= 2) {
|
||
|
cout << -1 << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
sort(arr.begin(), arr.end());
|
||
|
arr.insert(arr.begin(), 1, 0);
|
||
|
auto kp = arr.size()-1;
|
||
|
cout << max(arr[kp - 2], arr[kp] % arr[kp - 1]) << endl;
|
||
|
}
|