307597: CF1380D. Berserk And Fireball

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Berserk And Fireball

题意翻译

## 题目描述 有 $n$ 个战士站成一排,第 $i$ 个战士的战力是 $a_i$。所有战士的战力都是两两不同的。 你可以使用两种类型的咒语: 1. 火球术:你可以消耗 $x$ 点法力值来干掉连续的 $k$ 个战士(你必须干掉正好 $k$ 个,而不能干掉 $\le k$ 个)。 2. 狂暴术:你可以消耗 $y$ 点法力值,选择站在一起的两个战士使他们展开决斗,战力较弱的那个战士将会被干掉。 我们来举个例子,假设有 $7$ 个战士,其战力分别为 $[2,3,7,8,11,5,4]$,且此时的$k=3$($k$ 的定义详见火球术)。如果你对战力为 $8$ 与 $11$ 的两个战士施加狂暴术,剩下战士的战力将会变成 $[2,3,7,11,5,4]$(战力为 $8$ 的战士在决斗中战死)。然后如果我们对战力为 $[7,11,5]$ 的战士施加火球术,剩下战士的战力将会变成 $[2,3,4]$。 你想要组建一支军队,因此你想要将所有战士战力的序列从 $a_1,a_2,\cdots,a_n$ 变为 $b_1,b_2,\cdots,b_m$。试计算你所需的最少法力值。 ## 输入格式 第一行两个整数 $n,m (1\le n,m\le 2\cdot 10^5)$ ——序列 $a$ 的长度和序列 $b$ 的长度。 第二行三个整数 $x,k,y (1\le x,y\le 10^9,1\le k\le n)$ ——火球术消耗的法力值,火球术的范围和狂暴术消耗的法力值。 第三行 $n$ 个整数 $a_1,a_2,…,a_n (1\le a_i\le n)$。保证 $a_i$ 是两两不同的。 第四行 $m$ 个整数 $b_1,b_2,…,b_m(1\le b_i\le n)$。保证 $b_i$ 是两两不同的。 ## 输出格式 一行一个整数,即将序列从 $a_1,a_2,\cdots,a_n$ 变为 $b_1,b_2,\cdots,b_m$所需的最少法力值。如果无法完成变换,则输出$-1$。

题目描述

There are $ n $ warriors in a row. The power of the $ i $ -th warrior is $ a_i $ . All powers are pairwise distinct. You have two types of spells which you may cast: 1. Fireball: you spend $ x $ mana and destroy exactly $ k $ consecutive warriors; 2. Berserk: you spend $ y $ mana, choose two consecutive warriors and the warrior with greater power destroys another chosen warrior. For example, let the powers of warriors be $ [2, 3, 7, 8, 11, 5, 4] $ , and $ k = 3 $ . If you cast Berserk on warriors with powers $ 8 $ and $ 11 $ , the resulting sequence of powers becomes $ [2, 3, 7, 11, 5, 4] $ . Then, for example, if you cast Fireball on consecutive warriors with powers $ [7, 11, 5] $ , the resulting sequence of powers becomes $ [2, 3, 4] $ . You want to turn the current sequence of warriors powers $ a_1, a_2, \dots, a_n $ into $ b_1, b_2, \dots, b_m $ . Calculate the minimum amount of mana you need to spend on it.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ ( $ 1 \le n, m \le 2 \cdot 10^5 $ ) — the length of sequence $ a $ and the length of sequence $ b $ respectively. The second line contains three integers $ x, k, y $ ( $ 1 \le x, y, \le 10^9; 1 \le k \le n $ ) — the cost of fireball, the range of fireball and the cost of berserk respectively. The third line contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le n $ ). It is guaranteed that all integers $ a_i $ are pairwise distinct. The fourth line contains $ m $ integers $ b_1, b_2, \dots, b_m $ ( $ 1 \le b_i \le n $ ). It is guaranteed that all integers $ b_i $ are pairwise distinct.

输出格式


Print the minimum amount of mana for turning the sequnce $ a_1, a_2, \dots, a_n $ into $ b_1, b_2, \dots, b_m $ , or $ -1 $ if it is impossible.

输入输出样例

输入样例 #1

5 2
5 2 3
3 1 4 5 2
3 5

输出样例 #1

8

输入样例 #2

4 4
5 1 4
4 3 1 2
2 4 3 1

输出样例 #2

-1

输入样例 #3

4 4
2 1 11
1 3 2 4
1 3 2 4

输出样例 #3

0

Input

题意翻译

## 题目描述 有 $n$ 个战士站成一排,第 $i$ 个战士的战力是 $a_i$。所有战士的战力都是两两不同的。 你可以使用两种类型的咒语: 1. 火球术:你可以消耗 $x$ 点法力值来干掉连续的 $k$ 个战士(你必须干掉正好 $k$ 个,而不能干掉 $\le k$ 个)。 2. 狂暴术:你可以消耗 $y$ 点法力值,选择站在一起的两个战士使他们展开决斗,战力较弱的那个战士将会被干掉。 我们来举个例子,假设有 $7$ 个战士,其战力分别为 $[2,3,7,8,11,5,4]$,且此时的$k=3$($k$ 的定义详见火球术)。如果你对战力为 $8$ 与 $11$ 的两个战士施加狂暴术,剩下战士的战力将会变成 $[2,3,7,11,5,4]$(战力为 $8$ 的战士在决斗中战死)。然后如果我们对战力为 $[7,11,5]$ 的战士施加火球术,剩下战士的战力将会变成 $[2,3,4]$。 你想要组建一支军队,因此你想要将所有战士战力的序列从 $a_1,a_2,\cdots,a_n$ 变为 $b_1,b_2,\cdots,b_m$。试计算你所需的最少法力值。 ## 输入格式 第一行两个整数 $n,m (1\le n,m\le 2\cdot 10^5)$ ——序列 $a$ 的长度和序列 $b$ 的长度。 第二行三个整数 $x,k,y (1\le x,y\le 10^9,1\le k\le n)$ ——火球术消耗的法力值,火球术的范围和狂暴术消耗的法力值。 第三行 $n$ 个整数 $a_1,a_2,…,a_n (1\le a_i\le n)$。保证 $a_i$ 是两两不同的。 第四行 $m$ 个整数 $b_1,b_2,…,b_m(1\le b_i\le n)$。保证 $b_i$ 是两两不同的。 ## 输出格式 一行一个整数,即将序列从 $a_1,a_2,\cdots,a_n$ 变为 $b_1,b_2,\cdots,b_m$所需的最少法力值。如果无法完成变换,则输出$-1$。

加入题单

算法标签: