欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1709B.Also Try Minecraft
Also Try Minecraft
You are beta testing the new secret Terraria update. This update will add quests to the game!
Simply, the world map can be represented as an array of length , where the -th column of the world has height .
There are quests you have to test. The -th of them is represented by two integers and . In this quest, you have to go from the column to the column . At the start of the quest, you are appearing at the column .
In one move, you can go from the column to the column or to the column . In this version, you have Spectre Boots, which allow you to fly. Since it is a beta version, they are bugged, so they only allow you to fly when you are going up and have infinite fly duration. When you are moving from the column with the height to the column with the height , then you get some amount of fall damage. If the height is greater than the height , you get fall damage, otherwise you fly up and get damage.
For each of the given quests, determine the minimum amount of fall damage you can get during this quest.
Input
The first line of the input contains two integers and () — the number of columns in the world and the number of quests you have to test, respectively.
The second line of the input contains integers (), where is the height of the -th column of the world.
The next lines describe quests. The -th of them contains two integers and (), which means you have to move from the column to the column during the -th quest.
Note that can be greater than .
Output
Print integers. The -th of them should be the minimum amount of fall damage you can get during the -th quest completion.
Samples
7 6
10 8 9 6 8 12 7
1 2
1 7
4 6
7 1
3 5
4 2
2
10
0
7
3
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |