#P11096. Maximizing Separation After a Sorting Operation
Maximizing Separation After a Sorting Operation
Maximizing Separation After a Sorting Operation
The teacher wants to maximize the distance between two particular students after performing one sorting operation on a contiguous segment of the queue. The students stand at positions numbered from 1 to (n) and the distance between two students at positions (i) and (j) is defined as (|i - j|). For any pair of students originally at positions (i) and (j) with (1 \le i < j \le n), let (d(i,j)) denote the maximum possible distance that can be achieved after performing one sorting operation on a chosen contiguous segment. It can be observed that regardless of which pair is chosen, the teacher can always achieve a distance of (n-1) by, for example, selecting the entire sequence. Therefore, we have (d(i,j)=n-1).
The sum that needs to be computed is given by: [ \sum_{i=1}^{n-1} \sum_{j=i+1}^{n} d(i,j) = \sum_{i=1}^{n-1} \sum_{j=i+1}^{n} (n-1) = \frac{n (n-1)^2}{2}. ]
Given an integer (n), output the computed sum.
inputFormat
A single integer (n) representing the number of students.
outputFormat
A single integer representing the sum of the maximum achievable distances for all pairs.
sample
2
1