Problem list
Log in
#usaco0076 · USACO 2012-2013 January Silver

Square Overlap

Platinum V 2.0 s 256 MB

Farmer John is planning to build N (2 <= N <= 50,000) square fenced-in pastures on his farm, each of size exactly K x K (1 <= K <= 1,000,000). Pasture i is centered at point (x_i, y_i) with integer coordinates in the range -1,000,000...1,000,000. However, in his haste to complete his plans, FJ realizes that he may have accidentally placed two pastures in locations that overlap (by overlap, this means the two pastures share a positive area in common). No two pastures share the exact same center point.

Given the locations of each of the planned square pastures, please help FJ compute the area shared by the two overlapping pastures. Output zero if no two squares overlap, and -1 if overlap occurs between more than a single pair of pastures.

Input

  • Line 1: Two space-separated integers, N and K. K is guaranteed to be even.
  • Lines 2..1+N: Line i+1 contains the integers x_i and y_i, describing the center of the ith pasture.

Output

The area shared by the two overlapping squares. Output zero if no two squares overlap, and -1 if overlap occurs between more than a single pair of pastures.

Example 1

Input
4 6
0 0
8 4
-2 1
0 7
Output
20

Output details: Pastures #1 and #3 overlap in 20 units of area.

Source
USACO 2012-2013 January Silver
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code