CF703B.Mishka and trip
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.
Here are some interesting facts about XXX:
- XXX consists of n cities, k of whose (just imagine!) are capital cities.
- All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to c__i.
- All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 — 2 — ... — n — 1. Formally, for every 1 ≤ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
- Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 ≤ i ≤ n, i ≠ x, there is a road between cities x and i.
- There is at most one road between any two cities.
- Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals c__i·c__j.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products c__a·c__b. Will you help her?
小 Mishka 是一位出色的旅行家,曾游历过许多国家。在思考这次该去哪里旅行时,她选择了 XXX——一个美丽却鲜为人知的北方国度。
以下是关于 XXX 的一些有趣事实:
- XXX 由 n 座城市组成,其中 k 座(你敢相信吗!)是首都。
- 该国所有城市都很美丽,但每座城市各有其独特的美。第 i 座城市的美丽值为 ci。
- 所有城市通过道路依次相连,包括第 1 座与第 n 座城市,从而构成一个环形路线:1—2—…—n—1。形式上,对每个满足 1≤i<n 的 i,第 i 座城市与第 i+1 座城市之间有一条道路;此外,第 1 座城市与第 n 座城市之间也有一条道路。
- 每座首都城市均直接与其他所有城市相连。形式上,若城市 x 是首都,则对每个满足 1≤i≤n 且 i=x 的 i,城市 x 与城市 i 之间都有一条道路。
- 任意两座城市之间至多只有一条道路。
- 经过一条道路的费用直接取决于其所连接的两座城市的美丽值。因此,若城市 i 与城市 j 之间存在一条道路,则经过该道路的费用为 ci⋅cj。
Mishka 开始收拾行装准备出发,但尚未决定具体路线,于是她请你帮忙计算 XXX 中所有道路的费用总和。形式上,对每一对满足 a<b 且城市 a 与城市 b 之间存在道路的 (a,b),你需要计算所有乘积 ca⋅cb 的总和。你愿意帮她吗?
输入格式
The first line of the input contains two integers n and k (3 ≤ n ≤ 100 000, 1 ≤ k ≤ n) — the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers _c_1, _c_2, ..., c__n (1 ≤ c__i ≤ 10 000) — beauty values of the cities.
The third line of the input contains k distinct integers _id_1, _id_2, ..., id__k (1 ≤ id__i ≤ n) — indices of capital cities. Indices are given in ascending order.
输入的第一行包含两个整数 n 和 k(3≤n≤100000,1≤k≤n)—— 分别表示 XXX 国的城市总数以及其中首都城市的数量。
输入的第二行包含 n 个整数 c1,c2,…,cn(1≤ci≤10000)—— 表示各城市的美丽值。
输入的第三行包含 k 个互不相同的整数 id1,id2,…,idk(1≤idi≤n)—— 表示首都城市的索引。这些索引按升序给出。
输出格式
Print the only integer — summary price of passing each of the roads in XXX.
输出唯一的整数——经过 XXX 中每条道路的总费用。
输入输出样例
输入#1
4 1 2 3 1 2 3
输出#1
17
输入#2
5 2 3 5 2 2 4 1 4
输出#2
71
说明/提示
This image describes first sample case:

It is easy to see that summary price is equal to 17.
This image describes second sample case:

It is easy to see that summary price is equal to 71.
该图片描述了第一个样例:

容易看出,总价为 17。
该图片描述了第二个样例:

容易看出,总价为 71。
输入解题思路,AI测评打分。不知道怎么写?