#P15136. [SWERC 2025] Billion Players Game

[SWERC 2025] Billion Players Game

题目描述

You are following the world championship of the Billion Players Game. There are 10910^9 players competing, and you want to predict the final ranking pp of Godflex, your favorite streamer. After analyzing recent matches, you are sure that lprl \le p \le r, but you don’t know anything else.

There are nn offers made by the in-game bookmaker. In the ii-th offer, the bookmaker suggests an estimation aia_i for Godflex’s final ranking. For each offer, you must choose exactly one of the following actions:

  • Ignore the offer.
  • Accept the offer by claiming that paip \le a_i. If you are right, you earn pai|p - a_i| coins; otherwise you lose pai|p - a_i| coins.
  • Accept the offer by claiming that paip \ge a_i. If you are right, you earn pai|p - a_i| coins; otherwise you lose pai|p - a_i| coins.

After you decide how to deal with all the offers, the actual Billion Players Game is played. Godflex gets an integer position pp in [l,r][l, r], and then all the offers are settled up.

Your total score is the number of coins you are guaranteed to earn, that is, the minimum number of coins you earn over all possible values of pp in [l,r][l, r]. Find the maximum possible score you can guarantee.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains three integers n,l,rn, l, r (1n21051 \le n \le 2 \cdot 10^5, 1lr1091 \le l \le r \le 10^9) — the number of offers and the possible range of Godflex’s final ranking.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9) — the bookmaker’s estimations of Godflex’s ranking in each offer.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

输出格式

For each test case, output a single line containing an integer: the maximum possible score you can guarantee.

4
1 1 5
3
2 100 100
50 200
5 1 10
5 7 3 9 1
5 6 10
9 3 1 7 5
0
150
12
13

提示

Explanation of sample 1.

In the first test case, there is only one offer.

  • If you ignore the offer, your score is 0;
  • if you accept the offer claiming that p3p \le 3, your score is 2-2 (reached when p=5p = 5, which makes you lose 53=2|5 - 3| = 2 coins);
  • if you accept the offer claiming that p3p \ge 3, your score is 2-2 (reached when p=1p = 1, which makes you lose 13=2|1 - 3| = 2 coins).

So the maximum possible score is 0.

In the second test case, it is optimal to accept the offers claiming that p50p \ge 50 and p200p \le 200. Since pp must be 100, you gain 10050+100200=150|100 - 50| + |100 - 200| = 150 coins.