CodeForces 703A Mishka and trip
Description
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 ci.
- 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 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 betweena and 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.
Sample Input
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Hint
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个城市,普通城市会和下一个城市有一条连线,省会城市 会与其他所有城市都有一条边,边的权值是两个城市权值的乘积,求所有边的权值之和!
#include<cstdio>
#include<string.h>
long long a[],flag[];
int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(flag,,sizeof(flag));
long long sum=,ss=,i;
for(i = ; i <= n ; i++)
{
scanf("%lld",&a[i]);
sum+=a[i];
}
int b;
for(i = ; i < m ; i++)
{
scanf("%d",&b);
flag[b]=; //标记首都城市
}
for(i = ; i <= n ; i++)
{
if(flag[i] == )
{
sum-=a[i]; //减去首都城市的魅力系数
ss+=a[i]*sum;
}
}
for(i = ; i < n ; i++)
{
if(flag[i] != && flag[i+] != )
{
ss+=a[i]*a[i+];
}
}
if(flag[n] != && flag[] != )
ss+=a[n]*a[];
printf("%lld\n",ss);
}
}
CodeForces 703A Mishka and trip的更多相关文章
- Codeforces 703B. Mishka and trip 模拟
B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- CodeForces 703A Mishka and Game
简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...
- CodeForces 703B Mishka and trip
简单题. 先把环上的贡献都计算好.然后再计算每一个$capital$ $city$额外做出的贡献值. 假设$A$城市为$capital$ $city$,那么$A$城市做出的额外贡献:$A$城市左边城市 ...
- Codeforces Round #365 (Div. 2) Mishka and trip
Mishka and trip 题意: 有n个城市,第i个城市与第i+1个城市相连,他们边的权值等于i的美丽度*i+1的美丽度,有k个首都城市,一个首都城市与每个城市都相连,求所有边的权值. 题解: ...
- codeforces 703B B. Mishka and trip(数学)
题目链接: B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input stan ...
- cf703B Mishka and trip
B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 暑假练习赛 003 F Mishka and trip
F - Mishka and trip Sample Output Hint In the first sample test: In Peter's first test, there's on ...
- codeforces 703E Mishka and Divisors
codeforces 703E Mishka and Divisors 题面 给出大小为\(1000\)的数组和一个数\(k\),求长度最短的一个子序列使得子序列的元素之积是\(k\)的倍数,如果有多 ...
- Codeforces 703D Mishka and Interesting sum 离线+树状数组
链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到 ...
随机推荐
- RDL Web报表抛出ReportServerException,已取消该操作
::, RsBase() [ERROR] - Microsoft.Reporting.WebForms.ReportServerException: 已取消该操作. ---> System.Op ...
- 传智播客C++
轻松入门实战应用传智播客C++学院就业班第一阶段C提高课程 传智播客C提高讲义 传智扫地僧 1程序内存模型 1.1就业班引言 1.1.1问题引出 企业需要能干活的人 C学到什么程度可以找工作 ...
- Web前端体系的脉络结构
Web前端技术由 html.css 和 javascript 三大部分构成,是一个庞大而复杂的技术体系,其复杂程度不低于任何一门后端语言.而我们在学习它的时候往往是先从某一个点切入,然后不断地接触和学 ...
- iOS-Swift相比Objective-C有哪些优缺点
Swift,是苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序.它是一款易学易用的编程语言,而且 ...
- django之模版的自定义函数
- 自定义函数 simple_tag a. app下创建templatetags目录 b. 任意xxoo.py文件 c. 创建template对象 register d. __author__ = ' ...
- Java之栈空间和堆空间
1.变量的命名 (1)由字母,数字和下划线构成,首字母以字母或下划线开头 (2)变量的命名遵循见名知义 (3)Java变量命名建议不用中文 (4)变量名首字母建议不用大写字母开头 (5)用驼峰命名法命 ...
- 为Oracle Clusterware修改公用及私有网络接口
出于种种原因我们可能需要为已安装的Oracle集群软件修改其使用的公用或私有网络所使用的网络接口(How to Change Interconnect/Public Interface IP or S ...
- UVA439 knightMoves (A*启发搜索)
第一个A*,纪念下. A*要保证最短路一定要估价函数小于等于实际值,越接近越好 估价函数取Manhattan距离除以二. //Rey #include<cstdio> #include&l ...
- cdoj 414 八数码 (双向bfs+康拓展开,A*)
一道关乎人生完整的问题. DBFS的优越:避免了结点膨胀太多. 假设一个状态结点可以扩展m个子结点,为了简单起见,假设每个结点的扩展都是相互独立的. 分析:起始状态结点数为1,每加深一层,结点数An ...
- TDB文件介绍
samba在运行时,Samba 存储许多信息,从本地密码到希望从中收到信息的一系列客户端.这类数据其中一些是暂时的,在 Samba 重启时可能会被丢弃,但是另一些却是永久的,不会被丢弃.这类数据可能是 ...