#K94777. Maximum Taste Score Difference after Swap Operations
Maximum Taste Score Difference after Swap Operations
Maximum Taste Score Difference after Swap Operations
You are given n dishes with their taste scores and k swap operations. In each swap operation, the taste scores at two specified positions (1-indexed) are exchanged. After performing all the swap operations in order, determine the maximum difference between the taste scores of any two dishes.
The answer is computed as:
\(\text{Answer} = \max_{1 \leq i \leq n} A_i - \min_{1 \leq i \leq n} A_i\)
where \(A_i\) represents the taste score of the ith dish after all swaps.
inputFormat
The input is read from standard input (stdin). The first line contains two integers n and k, representing the number of dishes and the number of swap operations, respectively. The second line contains n space-separated integers representing the taste scores. Each of the following k lines contains two integers x and y, indicating that the taste scores at positions x and y (1-indexed) should be swapped.
outputFormat
Output to standard output (stdout) a single integer: the maximum difference between any two taste scores after performing all swap operations.## sample
5 2
10 20 30 40 50
1 5
2 4
40
</p>