B. Mishka and trip
time limit per test 1 second
memory limit per test 256 megabytes
input 

standard input

output 

standard output 

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:

  1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
  2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
  3. 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.
  4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every1 ≤ i ≤ n,  i ≠ x, there is a road between cities x and i.
  5. There is at most one road between any two cities.
  6. 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 ci·cj.

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 aand b you are to find sum of products ca·cb. Will you help her?

Input

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 c1, c2, ..., cn (1 ≤ ci ≤ 10 000) — beauty values of the cities.

The third line of the input contains k distinct integers id1, id2, ..., idk (1 ≤ idi ≤ n) — indices of capital cities. Indices are given in ascending order.

Output

Print the only integer — summary price of passing each of the roads in XXX.

Examples
input
4 1
2 3 1 2
3
output
17
input
5 2
3 5 2 2 4
1 4
output
71
Note

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.

有一点意思的模拟

n个城市形成一个环,一共n条边。此外这里头又有m个'vip城市'保证到其他城市都有边,一条连接i和j的边长度就是v[i]*v[j],问所有边的总长

其实还是sb题嘛

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<){printf("-");a=-a;}
if (a>=)write(a/);
putchar(a%+'');
}
inline void writeln(LL a){write(a);printf("\n");}
int n,m;
LL a[],b[];
LL ans,v;
bool mrk[];
int main()
{
n=read();m=read();
for (int i=;i<=n;i++)a[i]=read(),v+=a[i];
for (int i=;i<=m;i++)b[i]=read(),mrk[b[i]]=;
for (int i=;i<=m;i++)
{
ans+=a[b[i]]*(v-a[b[i]]);
v-=a[b[i]];
}
for(int i=;i<=n;i++)
{
int t=i+;if (t>n)t=;
if (!mrk[t]&&!mrk[i])ans+=a[i]*a[t];
}
printf("%lld\n",ans);
}

cf703B

最新文章

  1. Uva1624 Knots
  2. what linux java cpu 100% ?
  3. Material Design入门(三)
  4. linux下tomcat下部署项目如何打包压缩备份
  5. 函数buf_page_hash_get_low
  6. Java中String类的format方法使用总结
  7. WebApi2 jsonp跨域问题
  8. 《工作型PPT设计之道》培训心得
  9. Codeforces Round #327 (Div. 1) D. Top Secret Task
  10. opencart修改后台文件夹名
  11. Matlab中如何用命令方式保存图像?
  12. 关于无法下载android开发工具的解决方法
  13. 从零开始学习iftop流量监控(找出服务器耗费流量最多的ip和端口)
  14. java_IO流
  15. redis 通用函数
  16. Java IO网络编程经典模板
  17. sql backup
  18. 从零开始学习html(十)CSS格式化排版——上
  19. Yum Priorities
  20. Scripting.FileSystemObject对象的详细技巧指南

热门文章

  1. WCF 生产json对外的接口
  2. oracle数据表误删恢复
  3. xctool工具
  4. 设置css三种方法的优先级
  5. java 迭代器iterator
  6. Linux下JDK环境变量配置
  7. location传值
  8. js作用域与作用域链
  9. nginx+php,502错误
  10. splice从数组中删除指定定数据