#C11142. Arithmetic Progression Arrangement
Arithmetic Progression Arrangement
Arithmetic Progression Arrangement
You are given an array of n integers. Your task is to determine if it is possible to rearrange the array such that it forms an arithmetic progression.
An arithmetic progression is defined as a sequence in which the difference between consecutive elements is constant. In mathematical terms, a sequence \(a_1, a_2, \dots, a_n\) is an arithmetic progression if there exists a constant \(d\) such that \(a_{i+1} - a_i = d\) for all \(1 \le i < n\). Note that when \(n = 1\), the sequence is trivially considered an arithmetic progression.
Print YES
if the array can be rearranged to form an arithmetic progression, otherwise print NO
.
inputFormat
The input is read from standard input (stdin) and consists of two lines.
- The first line contains an integer
n
— the number of elements in the array. - The second line contains
n
space-separated integers representing the array.
outputFormat
Output a single line to standard output (stdout) containing YES
if the array can be rearranged to form an arithmetic progression, otherwise output NO
.
5
3 5 1 7 9
YES