编程介的小学生 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条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效