eolymp
bolt
Try our new interface for solving problems
Problems

King’s Puzzle

King’s Puzzle

King Kendrick is a sovereign ruler of Kotlin Kingdom. He is getting ready for the next session of the government. Kotlin Kingdom consists of $n$ cities. These cities need to be connected by several bidirectional roads. Since ministries are responsible for aspects of safety and comfort of the kingdom’s residents, some of them have made the following requirements: \begin{itemize} \item "All the cities should be connected by new roads" --- Ministry of Transport and Digital Infrastructure. \item "There may not be a loop road --- a road that connects a city with itself" --- Ministry of Environment. \item "There should be at most one road between a pair of cities" --- Treasury Department. \item "If $a_i$ is the number of roads connected to $i$-th city, then the set $\{a_1, ..., a_n\}$ should consist of exactly $k$ distinct numbers" --- Ministry of ICPC. \end{itemize} King Kendrick has issues with the requirements from the Ministry of ICPC. He asks you to help him. Find any set of roads that suits all the requirements above or say that it is impossible. \InputFile Two integers $n$ and $k~(1 \le k \le n \le 500)$. \OutputFile If it is impossible to satisfy all the requirements, output "\textbf{NO}" in the only line. Otherwise, output "\textbf{YES}" in the first line. Output $m~(0 \le m \le n \cdot (n - 1) / 2)$ --- the number of roads in the second line. Next $m$ lines should contain pairs of integers $a$ and $b~(1 \le a, b \le n)$ --- the cities to connect by a road. \includegraphics{https://static.eolymp.com/content/fa/fa8364dea4cfd2c564363b0f3bce0f9b26140213.gif}
Time limit 1 second
Memory limit 128 MiB
Input example #1
5 2
Output example #1
YES
4
1 2
1 3
1 4
1 5
Input example #2
4 1
Output example #2
YES
4
1 2
2 3
3 4
4 1
Source 2022 ICPC, NERC, December 7