Codeforces Round #782 (Div. 2) 1659C - Line Empire

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 0. There are n unconquered kingdoms at positions 0<x1<x2<…<xn. 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 c1) to any other conquered kingdom (let its position be c2) at a cost of a⋅|c1−c2|.
From the current capital (let its current position be c1) you can conquer an unconquered kingdom (let its position be c2) at a cost of b⋅|c1−c2|. 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 0 or one of x1,x2,…,xn. 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.

Input

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

The first line of each test case contains 3 integers n, a, and b (1≤n≤2⋅10^5; 1≤a,b≤10^5).

The second line of each test case contains n integers x_1,x_2,…,x_n (1≤x_1<x_2<…<x_n≤10^8).

The sum of n over all test cases does not exceed 2⋅105.

Output

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

Example input

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

Example output

173
171
75
3298918744


题意

有n个城市,国王想要征服每个城市,初始没有征服的城市,也没有定都的城市,令当前定都城市的坐标为c1,目标攻占城市为c2,征服一个城市的花费为a|c1-c2|,搬迁一个城市的花费为b|c1-c2|,给出所有城市的位置,问攻占所有城市所需要的的最小花费。

#include <iostream>
using namespace std;
typedef long long LL;
const int N = 200010;
int n,a,b;
int x[N],s[N];
int main () {
	int T;
	cin >> T;
	while (T--) {
		cin >> n >> a >> b;
		for (int i = 1;i <= n;i++) cin >> x[i];
		for (int i = 1;i <= n;i++) s[i] = s[i-1]+x[i];
		int last = 0;
		LL ans = 0;
		for (int i = 1;i <= n;i++) {
			ans += (LL)b*(x[i]-x[last]);
			if ((LL)(n-i)*b > a) {
				ans += (LL)a*(x[i]-x[last]);
				last = i;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
posted @   incra  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示