[gym102012C]Rikka with Consistency

time limit per test : 8.0 s
memory limit per test : 1024 MB

On the way to the Moscow, Rikka knows someone will replace her. Who is the guy? A devil to get in touch with her dark side, or an angel to rinse the shadow off her mind? However, Rikka knows that her successor has a special name, whose meaning in Chinese is Consistency. The process of replacement is so wonderful and sentimental, which is what you all must know.

Now, the only road from Beijing to Moscow is described as a broken line with n n n segments in the X − H X-H XH plane. The i-th segment connects the points ( i − 1 , h i − 1 ) (i−1,h_{i−1}) (i1,hi1) and ( i , h i ) (i,h_i) (i,hi), and h 0 = h n = 0 h_0=h_n=0 h0=hn=0 are known. This figure is a topographic map showing the whole trip from Beijing to Moscow and its H H H axis indicates the altitude. The distance of a path between two points is the length of the broken line between their corresponding points in the map.

At the outset of the trip, Rikka is in Beijing whose location in the X − H X-H XH plane is ( 0 , 0 ) (0,0) (0,0); Consistency, the guy who will replace Rikka, is in Moscow which is located at ( n , 0 ) (n,0) (n,0). Consistency always maintains consistent academic standards, a consistent life level, a consistent height of perspective and the altitude as what Rikka owns. This is why their heights are the same yesterday, today and forever.

Now Rikka wants you to calculate the minimum total distance they need (which is the total length of paths that Rikka and Consistency travel along). By the time that Rikka arrives in Moscow and Consistency arrives in Beijing as well, their replacement will be finished (and this is the ending which is also a new beginning).

Input

The input contains several test cases, and the first line contains a single integer T ( 1 ≤ T ≤ 500 ) T(1≤T≤500) T(1T500), the number of test cases.

For each test case, the first line contains a single integer n ( 1 ≤ n ≤ 50 ) n(1≤n≤50) n(1n50), the number of segments.
The second line contains ( n + 1 ) (n+1) (n+1) integers

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值