Permutation
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Now that Zenik has guessed his password for Algotester on the seventy-fourth try, he can solve a simple problem before bed, even from his phone.
Problem: find any permutation \((p_1, p_2, \ldots, p_n)\) of the sequence \((1, 2, \ldots, n)\) such that \[\sum_{i=1}^n |p_i - i|=|p_1-1|+|p_2-2|+\dots+|p_n-n|=k,\] or state that no such permutation exists.
Input
The single line contains two integers \(n\) and \(k\).
Output
In the first line, print YES or NO —
whether such a permutation exists or not.
If such a permutation exists, then in the second line print \(n\) integers \(p_i\) — the elements of the permutation that satisfy the condition.
Constraints
\(1 \le n \le 10^5\),
\(0 \le k \le 10^9\).
5 points: \(n \le 10\);
20 points: no additional constraints.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 4 4 | YES 1 4 2 3 |
Notes
Permutation — an ordered set without repetitions of the numbers \(1, 2, \ldots, n\).
In the example \(|p_1-1|+|p_2-2|+|p_3-3|+|p_4-4|=|1-1|+|4-2|+|2-3|+|3-4|=0+2+1+1=4\).
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|