CCC '23 S2 - Symmetric Mountains


Submit solution

Points: 1
Time limit: 1.0s
Python 3 30.0s
Memory limit: 1G

Problem types
Allowed languages
C++, Python

We will show why the fifth value from the left is \(2\) . Let us try to compute all the asymmetric values of crops with length \(5\) .

The height of the mountains in the first crop is \([3, 1, 4, 1, 5]\) . The asymmetric value of this crop is \(|3 - 5| + |1 - 1| + |4 - 4| = 2\) .

The height of the mountains in the second crop is \([1, 4, 1, 5, 9]\) . The asymmetric value of this crop is \(|1 - 9| + |4 - 5| + |1 - 1| = 9\) .

The height of the mountains in the last crop is \([4, 1, 5, 9, 2]\) . The asymmetric value of this crop is \(|4 - 2| + |1 - 9| + |5 - 5| = 10\) .

Hence, the most symmetric crop of length \(5\) is \(2\) .

Sample Input 2

4
1 3 5 6

Output for Sample Input 2

0 1 3 7

Explanation of Output for Sample Input 2

This sample satisfies the second subtask. Note that the only crop of length \(4\) is \([1, 3, 5, 6]\) which has an asymmetric value of \(|1 - 6| + |3 - 5| = 7\) .


Comments

There are no comments at the moment.