CF1659C.Line Empire

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers.

Consider a number axis. The capital of your empire is initially at 00. There are nn unconquered kingdoms at positions 0<x1<x2<…<xn0 \lt x_1 \lt x_2 \lt \ldots \lt x_n. You want to conquer all other kingdoms.

There are two actions available to you:

  • You can change the location of your capital (let its current position be c1c_1) to any other conquered kingdom (let its position be c2c_2) at a cost of a⋅∣c1−c2∣a\cdot |c_1-c_2|.
  • From the current capital (let its current position be c1c_1) you can conquer an unconquered kingdom (let its position be c2c_2) at a cost of b⋅∣c1−c2∣b\cdot |c_1-c_2|. You cannot conquer a kingdom if there is an unconquered kingdom between the target and your capital.

Note that you cannot place the capital at a point without a kingdom. In other words, at any point, your capital can only be at 00 or one of x1,x2,…,xnx_1,x_2,\ldots,x_n. Also note that conquering a kingdom does not change the position of your capital.

Find the minimum total cost to conquer all kingdoms. Your capital can be anywhere at the end.

你是一位雄心勃勃的国王,渴望成为“实数帝国”的皇帝。但在此之前,你必须先成为“整数帝国”的皇帝。

考虑一条数轴。你的帝国首都初始位于 00。在位置 0<x1<x2<…<xn0 \lt x_1 \lt x_2 \lt \ldots \lt x_n 处有 nn 个尚未征服的王国。你希望征服所有这些王国。

你有两种可执行的操作:

  • 你可以将首都(设其当前位置为 c1c_1)迁至任意一个已被征服的王国(设其位置为 c2c_2),花费为 a⋅∣c1−c2∣a\cdot |c_1-c_2|。
  • 从当前首都(设其当前位置为 c1c_1)出发,你可以征服一个尚未征服的王国(设其位置为 c2c_2),花费为 b⋅∣c1−c2∣b\cdot |c_1-c_2|。但若目标王国与首都之间存在至少一个尚未征服的王国,则你无法征服该目标王国。

注意:你不能将首都设在没有王国的位置上。换言之,在任意时刻,你的首都只能位于 00 或 x1,x2,…,xnx_1,x_2,\ldots,x_n 中的某一点。另外请注意:征服一个王国不会改变你首都的位置。

求征服所有王国所需的最小总花费。最终你的首都可以位于任意位置。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. The description of each test case follows.

The first line of each test case contains 33 integers nn, aa, and bb (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5; 1≤a,b≤1051 \leq a,b \leq 10^5).

The second line of each test case contains nn integers x1,x2,…,xnx_1, x_2, \ldots, x_n (1≤x1<x2<…<xn≤1081 \leq x_1 \lt x_2 \lt \ldots \lt x_n \leq 10^8).

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是每个测试用例的描述。

每个测试用例的第一行包含三个整数 nn、aa 和 bb(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5;1≤a,b≤1051 \leq a,b \leq 10^5)。

每个测试用例的第二行包含 nn 个整数 x1,x2,…,xnx_1, x_2, \ldots, x_n(1≤x1<x2<…<xn≤1081 \leq x_1 \lt x_2 \lt \ldots \lt x_n \leq 10^8)。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer — the minimum cost to conquer all kingdoms.

对于每个测试用例,输出一个整数——征服所有王国的最小代价。

输入输出样例

  • 输入#1

    4
    5 2 7
    3 5 12 13 21
    5 6 3
    1 5 6 21 30
    2 9 3
    10 15
    11 27182 31415
    16 18 33 98 874 989 4848 20458 34365 38117 72030

    输出#1

    173
    171
    75
    3298918744

说明/提示

Here is an optimal sequence of moves for the second test case:

  1. Conquer the kingdom at position 11 with cost 3⋅(1−0)=33\cdot(1-0)=3.
  2. Move the capital to the kingdom at position 11 with cost 6⋅(1−0)=66\cdot(1-0)=6.
  3. Conquer the kingdom at position 55 with cost 3⋅(5−1)=123\cdot(5-1)=12.
  4. Move the capital to the kingdom at position 55 with cost 6⋅(5−1)=246\cdot(5-1)=24.
  5. Conquer the kingdom at position 66 with cost 3⋅(6−5)=33\cdot(6-5)=3.
  6. Conquer the kingdom at position 2121 with cost 3⋅(21−5)=483\cdot(21-5)=48.
  7. Conquer the kingdom at position 3030 with cost 3⋅(30−5)=753\cdot(30-5)=75.

The total cost is 3+6+12+24+3+48+75=1713+6+12+24+3+48+75=171. You cannot get a lower cost than this.

以下是第二个测试用例的最优操作序列:

  1. 征服位置 11 处的王国,花费为 3⋅(1−0)=33\cdot(1-0)=3。
  2. 将首都迁至位置 11 处的王国,花费为 6⋅(1−0)=66\cdot(1-0)=6。
  3. 征服位置 55 处的王国,花费为 3⋅(5−1)=123\cdot(5-1)=12。
  4. 将首都迁至位置 55 处的王国,花费为 6⋅(5−1)=246\cdot(5-1)=24。
  5. 征服位置 66 处的王国,花费为 3⋅(6−5)=33\cdot(6-5)=3。
  6. 征服位置 2121 处的王国,花费为 3⋅(21−5)=483\cdot(21-5)=48。
  7. 征服位置 3030 处的王国,花费为 3⋅(30−5)=753\cdot(30-5)=75。

总花费为 3+6+12+24+3+48+75=1713+6+12+24+3+48+75=171。无法得到比这更低的花费。

输入解题思路,AI测评打分。不知道怎么写?

首页