编程介的小学生 2017-08-19 08:47 采纳率: 20.5%
浏览 772
已采纳

Sending Gift

Sending company has to send gift in the coming Christmas. One of the building of HangZhou which has 100 floors, there are many people working in the building will recieve gift in the coming Christmas. One of the staffer in the Sending company is dispatched to send gift to the tall building. It's so tired to send so many gift(but he has to do for money). Even worse there has no lift. Go up one floor cost 5 calories energy, Go down one floor cost 3 calories energy. The sending company aways use column to pack the gift, you can only fetch the gift at the two end of the column. Now the company pack these gift which sending to the tall building in two columns. Given the position(which floor) every gift has to send, now you are to find the min energy the staffer has to consume.

The staffer at the first floor at start.

Input

The first line if one integer P which is the test case.
Then P test follows,each test the first line if one integer N(N<=30) which is the number of gifts packed in the first column, the next line is N integers(between 1 and 100) which is the floor every gift (from one end to another) in the first column has to send.The next is one integer M(M<=30)which is the number of gifts packed in the second column, then next line is M integers (between 1 and 100) which is the floor every gift(from one end to another) in the second column has to send.

Output

Just one integer the min energy(calories) the staffer has to consume.

Sample Input

1
2
1 2
3
1 2 3

Sample Output

10

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料