Cyclic Rotation Paradigm (Contest)
Cyclic Rotation Paradigm (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Cyclic Rotation Paradigm (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement :
You are given an array A of size N. In one move, you can choose any subarray from this array and rotate it cyclically in any direction, any number of times. After exactly one such move, find the maximum value of AN - A1. Input The first line of the input contains a single integer N. The second line of the input contains N space seperated integers.
Constraints: 1 <= N <= 105 1 <= Ai <= 109 Output Print the maximum value of AN - A1 after performing the above operation exactly once. Example Sample Input: 4 2 1 8 1
Sample Output: 7
link: