救命!!!
70分!!!
最后三个点“WA”了
(⊙︿⊙)
求助!!!
错在哪里了?
QAQ
#include<bits/stdc++.h>
using namespace std;
bool b(int e,int f)
{
return e>f;
}
int n;
int a[100005],tmp1,tmp2;
int main()
{
cin >> n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a+1,a+n+1,b);
tmp1=2;
while(tmp1<=n && a[tmp1] == a[tmp1-1])
{
tmp1++;
}
tmp2=tmp1+1;
while(tmp2<=n && a[tmp2] == a[tmp2-1])
{
tmp2++;
}
if(tmp2 > n)
{
cout<<-1;
}
else if(tmp2 >n)
{
cout<<a[1] % a[tmp1];
}
else
{
cout<<max(a[tmp2],a[1] % a[tmp1]);
}
return 0;
}