-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCR365B.py
More file actions
33 lines (27 loc) · 860 Bytes
/
CR365B.py
File metadata and controls
33 lines (27 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from sys import stdin
numcity, numcap = map(int,stdin.readline().split())
beauty = list(map(int,stdin.readline().split()))
capitals = list(map(int,stdin.readline().split()))
presum=0
for i in range(len(beauty)):
if(i==len(beauty)-1):
presum+=(beauty[0]*beauty[i])
else:
presum+=(beauty[i]*beauty[i+1])
dic = dict()
board = [[0 for x in range(len(beauty))] for y in range(len(beauty))]
for i in capitals:
i-=1
right = (i+1) % (len(beauty))
left = ((i-1)+len(beauty))%len(beauty)
board[i][right]=1
board[i][left]=1
board[i][i]=1
for j in range(len(beauty)):
if(board[i][j]!=1):
presum+=(beauty[i]*beauty[j])
#print("Capital %d matching with city %d",(i+1,j+1))
board[i][j]=1
board[j][i]=1
#print(board)
print(presum)