atcoder#ARC144B. [ARC144B] Gift Tax

[ARC144B] Gift Tax

Score : 400400 points

Problem Statement

You are given positive integers aa and bb such that aba\leq b, and a sequence of positive integers A=(A1,A2,,AN)A = (A_1, A_2, \ldots, A_N).

On this sequence, you can perform the following operation any number of times (possibly zero):

  • Choose distinct indices i,ji, j (1i,jN1\leq i, j \leq N). Add aa to AiA_i and subtract bb from AjA_j.

Find the maximum possible value of min(A1,A2,,AN)\min(A_1, A_2, \ldots, A_N) after your operations.

Constraints

  • 2N3×1052\leq N\leq 3\times 10^5
  • 1ab1091\leq a\leq b\leq 10^9
  • 1Ai1091\leq A_i\leq 10^{9}

Input

Input is given from Standard Input in the following format:

NN aa bb

A1A_1 A2A_2 \ldots ANA_N

Output

Print the maximum possible value of min(A1,A2,,AN)\min(A_1, A_2, \ldots, A_N) after your operations.

3 2 2
1 5 9
5

Here is one way to achieve min(A1,A2,A3)=5\min(A_1, A_2, A_3) = 5.

  • Perform the operation with i=1,j=3i = 1, j = 3. AA becomes (3,5,7)(3, 5, 7).
  • Perform the operation with i=1,j=3i = 1, j = 3. AA becomes (5,5,5)(5, 5, 5).
3 2 3
11 1 2
3

Here is one way to achieve min(A1,A2,A3)=3\min(A_1, A_2, A_3) = 3.

  • Perform the operation with i=1,j=3i = 1, j = 3. AA becomes (13,1,1)(13, 1, -1).
  • Perform the operation with i=2,j=1i = 2, j = 1. AA becomes (10,3,1)(10, 3, -1).
  • Perform the operation with i=3,j=1i = 3, j = 1. AA becomes (7,3,1)(7, 3, 1).
  • Perform the operation with i=3,j=1i = 3, j = 1. AA becomes (4,3,3)(4, 3, 3).
3 1 100
8 5 6
5

You can achieve min(A1,A2,A3)=5\min(A_1, A_2, A_3) = 5 by not performing the operation at all.

6 123 321
10 100 1000 10000 100000 1000000
90688