AtCoder Regular Contest 161
翻译中…
Problem Statement
翻译中…
Let $N$ be a positive odd number. A sequence of integers of length $N$, $S = (S_1, S_2, \dots, S_N)$, is said to be M-type if "for each even number $i = 2, 4, \dots, N - 1$, it holds that $S_{i-1} < S_i$ and $S_i > S_{i+1}$".
翻译中…
You are given a sequence of positive integers of length $N$, $A = (A_1, A_2, \dots, A_N)$. Determine if it is possible to rearrange $A$ to be M-type.
翻译中…
Constraints
翻译中…
$1 \leq N \leq 2 \times 10^5$$N$is an odd number.$1 \leq A_i \leq 10^9 \ \ (1 \leq i \leq N)$
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N
A_1 \ A_2 \ \dots \ A_N
翻译中…
Output
翻译中…
If it is possible to rearrange the given integer sequence $A$ to be M-type, print Yes; otherwise, print No.
翻译中…
样例
Input #1
5
1 2 3 4 5
Output #1
Yes
The given sequence is $A = (1, 2, 3, 4, 5)$. After rearranging it, for example, to $B = (4, 5, 1, 3, 2)$,
- for $i = 2$, it holds that $B_1 = 4 < 5 = B_2$ and $B_2 = 5 > 1 = B_3$;
- for $i = 4$, it holds that $B_3 = 1 < 3 = B_4$ and $B_4 = 3 > 2 = B_5$.
Therefore, this sequence $B$ is M-type, and the answer is `Yes`.
Input #2
5
1 6 1 6 1
Output #2
Yes
The given sequence $A$ itself is M-type.
Input #3
5
1 6 6 6 1
Output #3
No
It is impossible to rearrange it to be M-type.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。