第一行输入一个正整数,代表站的数量。
第二行输入个正整数,前个数代表顺时针沿着公路走,站到第站之间的距离;最后一个正整数代表顺时针沿着公路走,第站到第 1 站的距离。·
第三行输入两个正整数和,代表小美的出发地和目的地。
一个正整数,代表小美走的最短距离。
3 1 2 2 2 3
2
3 1 2 2 1 3
2
def sol(n,arr,x,y): if x>=y: x,y = y-1,x-1 else: x,y = x-1,y-1 dis1 = [0]*n for i in range(1,n): dis1[i] = arr[i-1]+dis1[i-1] return min(dis1[y]-dis1[x],sum(arr)-dis1[y]+dis1[x]) while 1: try: n = int(input()) arr = list(map(int,input().split())) x,y = map(int,input().split()) ans = sol(n,arr,x,y) print(ans) except: break
N = int(input()) dis = [int(x) for x in input().split()] location = [int(y) for y in input().split()] distance_1 = 0 distance_2 = 0 for i in range(min(location)-1,max(location)-1): distance_1 += dis[i] dis[i] = 0 distance_2 = sum(dis) print(min(distance_1,distance_2))
importsys n = sys.stdin.readlines() num_station = int(n[0]) dist = n[1].strip().split() mindist = n[2].strip().split() start = int(mindist[0]) end = int(mindist[1]) res = float("inf") res2 = float("inf") res3 = float("inf") res4 = float("inf") ifstart > end: res2 = 0 res3 = 0 fori in range(start-1,num_station): res2 += int(dist[i]) fori in range(0,end-1): res2 += int(dist[i]) start,end = end,start fori in range(start-1,end-1): res3 += int(dist[i]) else: res = 0 res4 = 0 fori in range(start-1,end-1): res += int(dist[i]) start,end = end,start fori in range(start-1,num_station): res4 += int(dist[i]) fori in range(0,end-1): res4 += int(dist[i]) final= min(res,res2,res3,res4) print(final)