欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2179B.Blackslex and Showering
Blackslex and Showering
After his IMO medalist friend showered for two hours so that "he doesn't have to shower this again this week," Blackslex will be late for class!
In order to get to class, Blackslex must take the crowded elevator to many floors in a certain order. Because he is a hacker, he can skip visiting up to one floor without the other people knowing. His time taken is the sum of the absolute differences between consecutive floor numbers. Find the minimum time taken, given that he can skip up to one floor.
More formally, given an array of integers, you can choose up to one index to erase such that the sum $$ um_{i=1}^{n-2} |b_i - b_{i+1}|$$is minimized, where$b = [a\_1, \ldots, a\_{k-1}, a\_{k+1}, \ldots, a\_n]$is the array after erasing element. Report the minimum sum.
Input
The first line contains one integer () — the number of test cases.
The first line of each test case contains one integer () — the size of the array.
The second line contains integers ().
It is guaranteed that the sum of does not exceed over all test cases.
Output
For each test case, output a single real number — the minimum time taken.
Note
For the first test case, one optimal index to remove from is . The array becomes and the time taken is . For the second test case, the optimal index to remove is .
Samples
3
5
4 15 1 7 9
3
2 4 8
6
11 13 17 19 23 29
11
2
12
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |