Head office buildingProblem code: BUILDING |
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.
| Author: | anhdq |
| Date Added: | 5-05-2010 |
| Time Limit: | 1 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
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.

Fetching successful submissions
