Problem list
Log in
#usaco0144 · USACO 2013-2014 March Gold

The Lazy Cow (Gold)

Gold IV 2.0 s 256 MB

It's a hot summer day, and Bessie the cow is feeling quite lazy. She wants to locate herself at a position in her field so that she can reach as much delicious grass as possible within only a short distance.

There are N patches of grass (1 <= N <= 100,000) in Bessie's field. The ith such patch contains g_i units of grass (1 <= g_i <= 10,000) and is located at a distinct point (x_i, y_i) in the field (0 <= x_i, y_i <= 1,000,000). Bessie would like to choose a point in the field as her initial location (possibly the same point as a patch of grass, and possibly even a point with non-integer coordinates) so that a maximum amount of grass is within a distance of K steps from this location (1 <= K <= 2,000,000).

When Bessie takes a step, she moves 1 unit north, south, east, or west of her current position. For example, to move from (0,0) to (3,2) requires 5 total steps. Bessie does not need to take integer-sized steps.

Please help Bessie determine the maximum amount of grass she can reach, if she chooses the best possible initial location.

Input

  • Line 1: The integers N and K.
  • Lines 2..1+N: Line i+1 describes the ith patch of grass using 3 integers: g_i, x_i, y_i.

Output

The maximum amount of grass Bessie can reach within K steps, if she locates herself at the best possible initial position.

Example 1

Input
4 3
7 8 6
3 0 0
4 6 0
1 4 2
Output
8

Output details: By locating herself at (3,0), the grass at (0,0), (6,0), and (4,2) is all within K units of distance.

Source
USACO 2013-2014 March Gold
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