CodeChef: Codechef
Site under maintenance
  • Register
  • Forgot Password?
  • PRACTICE
    • Easy
    • Medium
    • Hard
  • COMPETE
    • August Mini Challenge
    • August Algorithm Challenge
    • July Algorithm Challenge
    • June Algorithm Challenge
    • May Gamers Challenge
  • DISCUSS
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef TechTalks
    • CodeChef Meetups
    • Campus Chapters
    • Host Your Contest
    • User Groups
  • HELP
    • Frequently Asked Questions
    • FAQ for Problem Setters
    • Tutorial: Paying Up
    • Tutorial: Small Factorials
    • Tutorial: Input and Output(I/O)
    • Tutorial: Your First Non-Trivial Problem
  • ABOUT
    • About CodeChef
    • About Directi
    • CEO's Corner
    • Press Room
    • Careers

Home » Problems (medium) » Head office building

Head office building

Problem code: BUILDING

  • Submit
  • All submissions

All submissions for this problem are available.

CodeChef Inc. owns a rectangular piece of land sized w×h. Its edges are parallel to the axes, with the bottom-left corner at (0,0) and top-right corner at (w,h). They intend to build a new head office within this land. The new office will be a square whose center is located at a point with integer coordinates, and whose diagonals are parallel to the axes and have length 2*d.

Unfortunately, there are n barricades on the land, some of which may need to be removed in order for the office to be built. The (i)th barricade is located at (Xi, Yi) and will cost Ci to remove. The office may only be built once all points it covers (including the boundaries) are free of barricades.

Request

Help them find the minimum total cost of barricade removal.

Input

  • The first line contains the integers w,h,d,n, respectively.
  • Within following n lines, the i-th line contains the integers Xi,Yi,Ci respectively.

Output

Output on a single line an integer which is the minimum cost found.

Example

Input:
4 3 1 4
1 3 5
3 3 4
2 2 1
2 1 2
Output:
2

Limitations

  • 2≤w,h≤1 000
  • 0≤n≤200 000
  • 2≤2d≤min(w,h)
  • 0<Ci≤10 000
  • All the listed barricades are inside or on the boundaries of the CodeChef’s land.
  • There is at most one barricade at each point.

  • Date:2010-05-05
    Time limit:1s
    Source limit:50000B
    Languages:All except: TCL


  • Submit

Comments

Loading Comments...

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Loading Submissions...

RECENT ACTIVITY FOR THIS PROBLEM:

Loading Recent Activity...

HELP

Program should read from standard input and write to standard output.

After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

If you are still having problems, see a sample solution here.

  • About CodeChef
  • About Directi
  • CEO's Corner
  • Careers
  • feedback@codechef.com

© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs

Sponsors
The time now is: