This page is still under construction.

Parts of this page are still being built. What you see may change.

Fortune at El Dorado

Time limit1sMemory limit128 MB

Summary
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 TT, the number of independent test cases. Each of the following TT blocks describes one test case.

The first line of a block contains two integers FF (0≤F≤10000 \le F \le 1000), the number of trees, and AA, the maximum allowed area. Each of the next FF lines contains two integers xx and yy (1≤x,y≤10001 \le x, y \le 1000), 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.

Examples2

  1. Example 1

    Input
    1
    3 3
    1 1
    1 3
    1 5
    
    Expected output
    2
    
  2. Example 2

    Input
    1
    4 1
    1 1
    1 2
    2 1
    2 2
    
    Expected output
    4