题目链接: http://codeforces.com/contest/354/problem/C
题解:
354C - Vasya and Beautiful Arrays
The problem was to find greatest d, such that ai ≥ d, ai mod d ≤ k holds for each i.
Let m = min(ai), then d ≤ m. Let consider two cases:
. In this case we will brute force answer from k + 1 to m. We can check, if number d is a correct answer in the following way:
We have to check that ai mod d ≤ k for some fixed d, which is equals to , where . Since all these intervals [x·d..x·d + k] doesn't intersects each with other, we can just check that , where cnt[l..r] — count of numbers ai in the interval [l..r].
Time complexity: O(maxA log maxA), proof is based on the sum of harmonic series.