NOI Contest Archive

Archive / 2024 / Qualifier Round

Rook Placement Puzzle

Medium · NOI 2024 Qualifier Round

Story

You are presented with a chessboard (N x N squares) and a bag overflowing with black rooks. Someone has already placed some white rooks (p of them) on the board in a seemingly random arrangement.

You are tasked with figuring out the maximum number of rooks such that none of these selected rooks are protected by each other. The number should be valid even if the arrangement is changed.

Then, you are tasked with figuring out the maximum number of black rooks that you can place on the board by rearranging white rooks and positioning black rooks such that no black rook is attacked by a white rook.

Challenge

Given the size of the chessboard (N) and the number of white rooks that has been already placed (p), determine the maximum number of white rooks that are always unprotected from each other. Also, find the maximum number of black rooks to be placed on the board by rearranging the formations such that no black rook is attacked by a white rook.

Input Format

Output Format

Constraints

Sample Input 0

8
20

Sample Output 0

3
12