luogu P5682 [times] great value

JX CSP-J day3 of t2, if I were JX players, I AK, and would not retired QAQ.

There is a very obvious conclusion:

- When the number of the de-emphasis> 2, then the next smallest value is strictly a large number of the third and the first two numbers taken mod max

- When to re-number = 2, Strictly small number of small value that is two

- When the number of de-duplication = 1, is no solution, output -1

Now talk about why the first established

First, the maximum number of mod other, can not do Strictly small value

Then, it is conceivable that the second largest and third largest is the biggest mod, apparently the second largest results than the third largest
to big results, so go the third largest, but it is possible much better than the second-largest largest mod the third large result better, then go to the former

Therefore, when the de-duplication, the number> time 2, $ Ans = max (thiMax, Max-secMax) $

After following the above conclusion, re-sorted to determine what you can

$Code:$

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
inline ll read(){
    register ll x=0,v=1,ch=getchar();
    while(!isdigit(ch)){if(ch=='-')v=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^'0');ch=getchar();}
    return x*v;
}
const ll MAX=200005;
ll n,a[MAX],b[MAX],tot;
int main(){
    n=read();
    for(register ll i=1;i<=n;++i){
        a[i]=read();
    }
    sort(a+1,a+1+n);
    b[++tot]=a[1];
    for(register ll i=2;i<=n;++i){
        if(a[i]!=a[i-1])b[++tot]=a[i];
    }
    if(tot==1)puts("-1");
    else if(tot==2){
        printf("%lld\n",max(b[1]%b[2],b[2]%b[1]));
    }else printf("%lld\n",max(b[tot]%b[tot-1],b[tot-2]));
    return 0;
}

  

  

Guess you like

Origin www.cnblogs.com/Lates/p/12040489.html