AmazonOA #70
Compute Min Delivery Time (Circular Drone Hubs)
估计简单可在线判题
考点(AI 标注)前缀和区间
The i-th transitionTime segment connects hub i and hub i+1, and the last segment connects m and 1; every segment can be traveled in both directions. Starting from 1, visit the requested hubs in order and find the minimum total time. With these edge weights, the answer to the source example is 3, not 4.
输入格式
The first line contains m n (1≤m≤5000, 1≤n≤200000), the second line contains m edge weights (1..1000000), and the third line contains n requested hub numbers (1..m).
输出格式
Output a single integer answer.
样例 1
输入:
3 4
5 2 1
1 3 3 2
输出:
3
样例 2
输入:
1 2
7
1 1
输出:
0
样例 3
输入:
2 2
2 3
2 1
输出:
4
样例说明
Example 1: 1→1 takes 0, 1→3 via the last edge takes 1, 3→3 takes 0, and 3→2 takes 2, for a total of 3. Example 2: there is only one hub, so the total time is 0. Example 3: of the two routes between the two hubs, take the shorter one, 2; two round trips total 4.