Wuyi nod 1421 Max MoD value

Source: Internet
Author: User

1421 Max MoD valuetitle Source: Codeforcesbase time limit: 1 seconds space limit: 131072 KB score: 80 Difficulty: 5-level algorithm problem

There is an an an array of n integers. Now you want to find two numbers (can be the same one)ai,aJ Makesai mod aJ Max and ai ≥ aJ.

Input
A single set of test data. The first line contains an integer n, which represents the size of the array A. (1≤n≤2*10^5) The second line has n spaces separated by an integer AI (1≤ai≤10^6).
Output
Output An integer representing the maximum mod value.
Input Example
33 4 5
Output Example
2

/*51 nod 1421 Max mod value problem: Select two numbers from the array to make A[I]%A[J] maximum solve: You can find A[i] a multiple of the closer to A[j] the greater. So enumerate the multiples of a[j] and then two points to find. At first I thought this would be t .... m+m/2+ ... M=o (MLGM) hhh-2016/09/16-16:33:10*/#pragma comment (linker, "/stack:124000000,124000000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <vector > #include <math.h> #include <queue> #include <set> #include <map> #define Lson i<<1# Define Rson i<<1|1#define ll long Long#define CLR (A, B) memset (A,b,sizeof (a)) #define SCANFI (a) scanf ("%d", &a) # Define SCANFS (a) scanf ("%s", a) #define SCANFL (a) scanf ("%i64d", &a) #define SCANFD (a) scanf ("%lf", &a) #define Key _val ch[ch[root][1]][0] #define EPS 1e-7#define inf 0x3f3f3f3f3f3f3f3fusing namespace std;const ll mod = 1e9+7;const int ma    xn = 200010;const Double PI = ACOs ( -1.0); Template<class t> void Read (t&num) {char CH;    BOOL F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 '; f= ch== '-', Ch=getchar ()); for (num=0; ch>= ' 0 ' &&ch<= ' 9 ';    num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);}        int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0");    Return    } while (p) stk[++ TP] = p%10, p/=10;    while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');}    int A[maxn];int Main () {int n;    Read (n);    for (int i =0; i < n; i++) {read (a[i]);    } sort (a,a+n);//int cnt = unique (a,a+n)-A;    int ans = 0;        for (int i =0; i < n; i++) {if (a[i] = = 1) continue;            for (int j = 1;j <= a[n-1]/a[i] + 1; j + +) {int pos = lower_bound (A+I,A+N,J * a[i])-A;            POS--;            if (pos > 0 && pos <= n && a[pos] > A[i]) ans = max (ans, a[pos]% a[i]); if (ans = = a[i]-1) break;//cout << J << "<< pos <<" "<<ans &L        t;< Endl; }} print (ANS); return 0;}

  

Wuyi nod 1421 Max MoD value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.