#P10991. [蓝桥杯 2023 国 Python A] 选段排序

[蓝桥杯 2023 国 Python A] 选段排序

Problem Description

Given a sequence AiA_i of length nn and two indices p,qp, q (p<q)(p < q). You may choose any interval [L,R][L, R] and sort the elements in this range, ALARA_L \sim A_R, in nondecreasing order.

Find the maximum possible value of AqApA_q - A_p after sorting exactly one chosen interval.

Input Format

The first line contains three integers n,p,qn, p, q, separated by a single space.

The second line contains nn integers, representing A1,A2,,AnA_1, A_2, \cdots, A_n, separated by a single space.

Output Format

Output one line containing one integer, the maximum value of AqApA_q - A_p.

5 1 4
4 5 3 3 1

3

Hint

For 20%20\% of the test cases, n100n \le 100 and Ai200A_i \le 200.

For 40%40\% of the test cases, n2000n \le 2000 and Ai3000A_i \le 3000.

For all test cases, Constraints: 1pqn2×1051 \le p \le q \le n \le 2 \times 10^5, 1Ai1061 \le A_i \le 10^6.

Translated by ChatGPT 5