cswork / OAOpen practice workspace

AmazonOA #184

Find Optimal Level

Estimated MediumJudge-ready

Topics (AI-labelled)Binary SearchGreedy

In one operation, choose two different positions: add incVal to one inventory and subtract decVal from the other; incVal≤decVal. The operation may be performed any number of times, and in the end every inventory must be strictly positive (negative values are allowed along the way). Maximize the final minimum inventory.

Input

The first line contains n incVal decVal; the second line contains the inventories. 2≤n≤200000; inventories 1..10^9; 1≤incVal≤decVal≤10^9.

Output

Output a single integer, the answer.

Example 1

Input:

2 2 3
1 9

Output:

3

Example 2

Input:

2 1 1
5 5

Output:

5

Example 3

Input:

3 1 2
1 2 3

Output:

1

Example notes

The answers are 3, 5 and 1.

Editorial

Loading solution…