CF1709B.Also Try Minecraft
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 n , where the i -th column of the world has height ai .
There are m quests you have to test. The j -th of them is represented by two integers sj and tj . In this quest, you have to go from the column sj to the column tj . At the start of the quest, you are appearing at the column sj .
In one move, you can go from the column x to the column x−1 or to the column x+1 . 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 p to the column with the height q , then you get some amount of fall damage. If the height p is greater than the height q , you get p−q fall damage, otherwise you fly up and get 0 damage.
For each of the given quests, determine the minimum amount of fall damage you can get during this quest.
输入格式
The first line of the input contains two integers n and m ( 2≤n≤105;1≤m≤105 ) — the number of columns in the world and the number of quests you have to test, respectively.
The second line of the input contains n integers a1,a2,…,an ( 1≤ai≤109 ), where ai is the height of the i -th column of the world.
The next m lines describe quests. The j -th of them contains two integers sj and tj ( 1≤sj,tj≤n;sj=tj ), which means you have to move from the column sj to the column tj during the j -th quest.
Note that sj can be greater than tj .
输出格式
Print m integers. The j -th of them should be the minimum amount of fall damage you can get during the j -th quest completion.
输入输出样例
输入#1
7 6 10 8 9 6 8 12 7 1 2 1 7 4 6 7 1 3 5 4 2
输出#1
2 10 0 7 3 1