编程介的小学生 2017-05-13 14:48 采纳率: 20.5%
浏览 766
已采纳

Ferry Lanes

Description

Arthur lives in a small city which is partitioned into two districts, the northern and the southern, by a river flowing through. The northern and southern districts are connected by N + 1 bidirectional ferry lanes, numbered 0 to N from west to east. Each ferry lane connects two docks in separate sides of the river. No two lanes share the same dock or cross each other.

Today Arthur needs to deliver a package from one dock to another. He knows the sailing time of each ferry lane and the time cost by walking from one dock to an adjacent one along the river bank. Arthur wants to know what is the minimum time his delivery will cost.

Input

The input consists of several test cases. The first line of each consists an integer N ( 1 ≤ N ≤ 1,000,000). The second line consists of two pairs of integers describing the starting and finishing docks, where the first of each pair represents the district (0 means northern and 1 means southern) and the second represents the lane number. The third line contains N integers describing the time cost by walking between two adjacent docks on the northern bank from lane0 to laneN. The fourth line contains N + 1 integers describing the sailing time of each ferry lane. The last line contains N integers describing the time cost by walking between two adjacent docks on the southern bank from lane0 to laneN. N = 0 indicates the end of input.

Output

For each test cases output one line contains the minimum time. You may assume the answer fits in a signed 64-bit integer.

Sample Input

4
0 0 1 4
1 3 5 7
3 5 1 3 7
1 3 7 5
0
Sample Output

17

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-31 02:59
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器