CF1767E.Algebra Flash

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Algebra Flash 2.2 has just been released!

Changelog:

  • New gamemode!

Thank you for the continued support of the game!

Huh, is that it? Slightly disappointed, you boot up the game and click on the new gamemode. It says "Colored platforms".

There are nn platforms, numbered from 11 to nn, placed one after another. There are mm colors available in the game, numbered from 11 to mm. The ii-th platform is colored cic_i.

You start on the platform 11 and want to reach platform nn. In one move, you can jump from some platform ii to platforms i+1i + 1 or i+2i + 2.

All platforms are initially deactivated (including platforms 11 and nn). For each color jj, you can pay xjx_j coins to activate all platforms of that color.

You want to activate some platforms so that you could start on an activated platform 11, jump through some activated platforms and reach an activated platform nn.

What's the smallest amount of coins you can spend to achieve that?

代数速算 2.2 版本刚刚发布!

更新日志:

  • 新增游戏模式!

感谢大家对本游戏的持续支持!

嗯?就这些?你略感失望,但还是启动了游戏,并点击进入新游戏模式。屏幕上显示:“彩色平台”。

共有 nn 个平台,编号从 11 到 nn,依次排列。游戏中共有 mm 种颜色,编号从 11 到 mm。第 ii 个平台的颜色为 cic_i。

你起始于平台 11,目标是到达平台 nn。每次移动,你可以从某个平台 ii 跳到平台 i+1i + 1 或 i+2i + 2。

所有平台初始均处于未激活状态(包括平台 11 和平台 nn)。对于每种颜色 jj,你可以花费 xjx_j 枚金币来激活所有该颜色的平台。

你需要激活若干平台,使得你能从已激活的平台 11 出发,经过一系列已激活的平台跳跃,最终抵达已激活的平台 nn。

请问:达成上述目标所需的最少金币数量是多少?

输入格式

The first line contains two integers nn and mm (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5; 1≤m≤401 \le m \le 40) — the number of platforms and the number of colors, respectively.

The second line contains nn integers c1,c2,…,cnc_1, c_2, \dots, c_n (1≤ci≤m1 \le c_i \le m) — the colors of the platforms.

The third line contains mm integers x1,x2,…,xmx_1, x_2, \dots, x_m (1≤xi≤1071 \le x_i \le 10^7) — the cost of activating all platforms of each color.

第一行包含两个整数 nn 和 mm(2≤n≤3⋅1052 \le n \le 3 \cdot 10^5;1≤m≤401 \le m \le 40),分别表示平台的数量和颜色的种类数。

第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \dots, c_n(1≤ci≤m1 \le c_i \le m),表示各平台的颜色。

第三行包含 mm 个整数 x1,x2,…,xmx_1, x_2, \dots, x_m(1≤xi≤1071 \le x_i \le 10^7),表示激活每种颜色的所有平台所需的费用。

输出格式

Print the smallest amount of coins you can spend to activate some platforms so that you could start on an activated platform 11, jump through some activated platforms and reach an activated platform nn.

输出激活若干平台所需的最少硬币数量,使得你可以从已激活的平台 11 出发,经过若干已激活的平台跳跃,最终到达已激活的平台 nn。

输入输出样例

  • 输入#1

    5 3
    1 3 2 3 1
    1 10 100

    输出#1

    11
  • 输入#2

    5 3
    1 3 2 3 1
    1 200 20

    输出#2

    21
  • 输入#3

    4 2
    2 2 1 1
    5 5

    输出#3

    10
  • 输入#4

    10 10
    3 8 6 2 10 5 2 3 7 3
    9 7 4 2 1 8 2 6 2 2

    输出#4

    15

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

首页