AmazonOA #137
Drone Delivery Route
估计简单可在线判题
考点(AI 标注)前缀和区间
m stations form a two-way ring, and the edge lengths give the flight time between adjacent stations. The drone starts at station 1 and must reach all requested stations in order; find the minimum total time. A repeated visit to the same station requires no movement.
输入格式
The first line contains m q, the second line contains m edge lengths, and the third line contains q 1-based requested stations. 1≤m,q≤100000, edge lengths 1..10^9.
输出格式
Output a single integer answer.
样例 1
输入:
3 4
3 2 1
1 3 3 2
输出:
3
样例 2
输入:
4 3
5 1 2 6
2 4 1
输出:
14
样例 3
输入:
1 2
7
1 1
输出:
0
样例说明
Example 1: 1→1 costs 0, 1→3 costs 1, 3→3 costs 0, and 3→2 costs 2, for a total of 3. Example 2: costs 5, 3 and 6, for a total of 14. Example 3: the drone always stays at the only station, so the answer is 0.