C - AtCoder Riko 解説 by en_translator
Original proposer: ynymxiaolongbao
Without loss of generality, we may assume that \(A_1,A_2,\dots,A_N\).
We consider the two cases: whether all AtCoderikos broke into two pieces or not.
(1) If all AtCoderikos broke into two pieces
First, it is necessary that \(N\) is even.
Since the AtCoderiko paired with length-\(A_1\) AtCoderiko has a length less than or equal to \(A_N\), we have \(L \leq A_1+A_N\).
Similarly, considering the AtCoderiko paired with length-\(A_N\) AtCoderiko, we see that \(A_1+A_N \leq L\).
Therefore, \(A_1+A_N=L\), and we can pair the length-\(A_1\) and length-\(A_N\) AtCoderikos.
Likewise, \((A_2,A_{N-1}),(A_3,A_{N-2}) \dots,(A_{\frac{N}{2}},A_{\frac{N}{2}+1})\) can be paired, and it is necessary that each pair sums to \(A_1+A_N\).
Conversely, if this holds, then setting \(L=A_1+A_N\) satisfies the conditions.
\((2)\) If there is an AtCoderiko that did not break into two
The longest AtCoderiko did not break into two, so we see that \(L=A_N\).
We also see that all AtCoderiko of length \(A_N\) remained unbroken, while those shorter than \(A_N\) are the result of being broken.
For AtCoderikos of length less than \(A_N\), we can use the same algorithm as (1).
The problem can be solved by inspecting these cases.
The complexity is \(O(N\log N)\), where the sort is the bottleneck.
投稿日時:
最終更新: