Candy Tribulation

AtCoder
IDabc432_c
Time2000ms
Memory256MB
Difficulty
You have an unlimited supply of two types of candies: small candies and large candies. The weight of a small candy is $X$ grams, and the weight of a large candy is $Y$ grams. Large candies are heavier than small candies (that is, $X < Y$). There are $N$ children, numbered $1$ to $N$. You have decided to distribute candies so that the following conditions are satisfied: * For $i=1,\dots,N$, child $i$ receives exactly $A_i$ candies in total of the two types. * The total weights of candies distributed to the $N$ children are all equal. Determine whether there exists a distribution method that satisfies the conditions. If it exists, find the maximum possible value for the number of large candies distributed. ## Constraints * $2 \leq N \leq 2 \times 10^5$ * $1 \leq A_i \leq 10^9$ * $1 \leq X < Y \leq 10^9$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $X$ $Y$ $A_1$ $\dots$ $A_N$ [samples]
Samples
Input #1
3 6 8
11 10 13
Output #1
18

You can distribute candies as follows so that the total weights of candies distributed to the children are all equal.

*   Child $1$ receives $4$ small candies and $7$ large candies. The total weight is $6 \times 4 + 8 \times 7 = 80$ grams.
*   Child $2$ receives $0$ small candies and $10$ large candies. The total weight is $6 \times 0 + 8 \times 10 = 80$ grams.
*   Child $3$ receives $12$ small candies and $1$ large candy. The total weight is $6 \times 12 + 8 \times 1 = 80$ grams.

In this distribution method, a total of $18$ large candies are distributed.
There is no distribution method that satisfies the conditions and distributes more than $18$ large candies. Therefore, the answer is $18$.
Input #2
2 3 4
3 5
Output #2
\-1

There is no distribution method that satisfies the conditions.
Input #3
8 4 32
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Output #3
8000000000

The answer may not fit in a 32-bit integer.
API Response (JSON)
{
  "problem": {
    "name": "Candy Tribulation",
    "description": {
      "content": "You have an unlimited supply of two types of candies: small candies and large candies. The weight of a small candy is $X$ grams, and the weight of a large candy is $Y$ grams. Large candies are heavier",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc432_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You have an unlimited supply of two types of candies: small candies and large candies. The weight of a small candy is $X$ grams, and the weight of a large candy is $Y$ grams. Large candies are heavier...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments