Point:40
Problem:MLE
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
ll a[n];
vector<ll> mod;
for(int i = 0; i < n; i++){
cin >> a[i];
for(int j = 0; j < i; j++){
mod.push_back(a[i] % a[j]);
mod.push_back(a[j] % a[i]);
}
}
sort(mod.begin(), mod.end());
ll now = mod[mod.size() - 1];
for(int i = mod.size() - 2; i >= 0; i--)
if (now != mod[i]){
cout << mod[i];
return 0;
}
cout << -1;
}