#P16212. [ECUSTPC 2025] 秋色堡垒

    ID: 18227 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>贪心2025排序前缀和高校校赛

[ECUSTPC 2025] 秋色堡垒

Problem Description

Maddy has arrived in front of the fortress in autumn. She collected nn ingredients, whose freshness values are a1,a2,,ana_1, a_2, \dots, a_n.

Maddy will use these ingredients to cook dinners for several days. In particular, since she only has two recipes with skill values xx and yy, she will cook exactly two dishes every day, not one less.

The cooking process for each day is as follows:

  • Maddy may pick two different ingredients that have not been picked before, in any order. Let their freshness values be aa and bb. Then she cooks them, assigning one recipe to each ingredient. The deliciousness values of the two dishes are axax and byby, so the total deliciousness of that day's dinner is ax+byax + by. Note that Maddy may assign the two ingredients to the two recipes in any order, and each day's dinner must use 2 different ingredients to make 2 dishes.

Please help Maddy choose how many days to cook dinner, and compute the maximum possible total deliciousness DD over those days. (Of course, if everything tastes terrible, she can also choose not to cook at all, i.e., the number of days can be 00.)

Input Format

The first line contains an integer TT (1T1051 \le T \le 10^5), the number of test cases.

For each test case, the first line contains three integers n,x,yn, x, y (2n105,106x,y1062 \le n \le 10^5, -10^6 \le x, y \le 10^6), representing the number of ingredients and the skill values of the two recipes.

The next line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (106ai106-10^6 \le a_i \le 10^6), representing the freshness of each ingredient.

It is guaranteed that n3×105\sum n \le 3 \times 10^5 over all test cases.

Output Format

For each test case, output one integer DD in one line, representing the maximum possible total deliciousness over those days.

6
4 1 2
4 5 6 7
5 2 8
0 -1 -2 -6 7
6 -1 -2
1 2 3 4 5 6
6 3 4
-1 0 0 1 2 3
6 -3 -4
1 0 0 -1 -2 -3
5 1 -10
-9 2 -5 3 -7
35
56
0
23
23
165

Hint

Explanation for Sample 1

For the 1st sample, we consider cooking dinner for 2 days:

  • On day 1, choose ingredients with freshness 77 and 55, and assign them to the recipes with skill values 22 and 11, respectively. The dinner has deliciousness 7×2+5×1=197 \times 2 + 5 \times 1 = 19;
  • On day 2, choose ingredients with freshness 66 and 44, and assign them to the recipes with skill values 22 and 11, respectively. The dinner has deliciousness 6×2+4×1=166 \times 2 + 4 \times 1 = 16.

The total deliciousness is 3535.

For the 2nd sample, we consider cooking dinner for 1 day: choose ingredients with freshness 77 and 00, and assign them to the recipes with skill values 88 and 22, respectively. The dinner has deliciousness 7×8+0×2=567 \times 8 + 0 \times 2 = 56.

For the 3rd sample, we consider not cooking dinner, because in any case the deliciousness of the dinner is negative.

Translated by ChatGPT 5