Fortune at El Dorado
Time limit1sMemory limit128 MB
Given up to 1000 points on a 1000x1000 grid and a maximum area A, find an axis-parallel rectangle with positive integer area at most A containing the most points.
- Level
Hard8 of 10
- Topics
- Two pointers, Binary search, Prefix sum, Sorting
- Solved
- No attempts yet
Problem
On his fabulous trip to El Dorado, Kamran made his fortune. After helping the king solve a difficult math problem, the king granted him a piece of the royal garden. The king wrote a letter to the gardener asking that a rectangular region of the royal garden, with a specified area, be given to Kamran. (In El Dorado the trees are made of gold!)
When Kamran brought the letter to the gardener, he learned that the trees are scattered with no particular pattern. To maximize his profit, Kamran convinced the gardener that it would be acceptable to let Kamran choose the position of his rectangular share, and even to take a share smaller than the letter specifies. The gardener only insisted that:
- the sub-garden's sides be parallel to the sides of the garden (which is itself a rectangle),
- its vertices have integer coordinates, and
- its area be positive (so the king would not grow suspicious).
Given the positions of the trees and the maximum allowed area of his share, help Kamran find an axis-parallel rectangular sub-garden, with positive area not exceeding the allowed area, that contains the greatest number of trees. A tree lying on the border of the sub-garden counts as inside.
Input
The first line contains a single integer , the number of independent test cases. Each of the following blocks describes one test case.
The first line of a block contains two integers (), the number of trees, and , the maximum allowed area. Each of the next lines contains two integers and (), the position of a tree. No two trees share the same position.
Output
For each test case, print a single line containing one integer: the maximum number of trees Kamran can obtain.