## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Also Try Minecraft Codeforces Solution

B. Also Try Minecraft
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ${a}_{i}$.

There are $m$ quests you have to test. The $j$-th of them is represented by two integers ${s}_{j}$ and ${t}_{j}$. In this quest, you have to go from the column ${s}_{j}$ to the column ${t}_{j}$. At the start of the quest, you are appearing at the column ${s}_{j}$.

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

Solution Click Below:-  👉
👇👇👇👇👇

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.

Input

The first line of the input contains two integers $n$ and $m$ ($2\le n\le {10}^{5};1\le m\le {10}^{5}$) — the number of columns in the world and the number of quests you have to test, respectively.

Three Doors Codeforces Solution 2022

Also Try Minecraft Codeforces Solution

Recover an RBS Codeforces Solution

Rorororobot Codeforces Solution

XOR Tree Codeforces Solution

Multiset of Strings Codeforces Solution

The second line of the input contains $n$ integers ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($1\le {a}_{i}\le {10}^{9}$), where ${a}_{i}$ 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 ${s}_{j}$ and ${t}_{j}$ ($1\le {s}_{j},{t}_{j}\le n;{s}_{j}\ne {t}_{j}$), which means you have to move from the column ${s}_{j}$ to the column ${t}_{j}$ during the $j$-th quest.

Note that ${s}_{j}$ can be greater than ${t}_{j}$.

Output

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.