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

Fetching successful submissions

Hi Admin, Seems that the
Hi Admin,
Seems that the answer to sample problem is 1.
if a square is drawn taking its center at (3,1), then the problem needs only "2 2 1" barricade to be removed.
Please see and verify if i am wrong.
Regards,
Manu
@Manu Ram Pandit: it costs 2
@Manu Ram Pandit: it costs 2 to remove the baricade at (2, 1) if you put the square center at (3, 1), please check the statement again ;)
just one test case?
just one test case?
@jayesh dhamechai: it may
@jayesh dhamechai: it may have several test cases (each follows above i/o format), and you will get accepted (and receive one point) when you can solve ALL of them :-)
so we need to process input
so we need to process input till EOF?
@jayesh dhamechai: oh no,
@jayesh dhamechai: oh no, each test case is like a separated file following the above i/o format which you must process, please see FAQ if you have any problems with the CodeChef judge system
Hi, I agree with Manu - the
what does it mean when they
what does it mean when they say first line
do we have to read a line and then scan respective values of variables from it or scan values for each variable one by one
and why do we get runtime error (other)
it says in faq that it is due to too much memory but my result shows 1.6 m while many currect submissions are showing 17,30,18m ?
please help
"...with the bottom-left
"...with the bottom-left corner at (0,0) and top-right corner at (w,h).."
Taking this into consideration, the answer should be 1 to the test case.
@admin: pls check.
@Karthik: The statement said
@Karthik: The statement said "The office may only be built once all points it covers (including the boundaries) are free of barricades." so if you put a square centering at (1, 2), you must still remove the baricade at (2, 1) which costs 2, ok ?
@lalit mohan chawla: please see the FAQ for the instructions of i/o :-) the statement is clear.
not only overflowing memory causes runtime error, please check your code again ;)
@Karthik: (again) please
@Karthik: (again) please check the problem statement again, you may misunderstand somewhere :-)
how large can the inputs
how large can the inputs be?
any ranges?
can we consider all as unsigned integers?
@Indraneel P: please check
@Indraneel P: please check the limitations part for details, all are clear ;-)
OOPS........ 2min late to
OOPS........
2min late to submit! :(
when will this be posted to
when will this be posted to practice problems?
I wan't to check whether my solution is correct.