Head office 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.
Help them find the minimum total cost of barricade removal.
- 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 on a single line an integer which is the minimum cost found.
4 3 1 4 1 3 5 3 3 4 2 2 1 2 1 2
- 2≤w,h≤1 000
- 0≤n≤200 000
- 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.
|Tags||anhdq, cook01, medium|
|Time Limit:||0.111317 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.