CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » July Cook Off  » Head office building

Head office building

Problem code: BUILDING

  • 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.
  •  


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


  • Submit

Comments

  • Login or Register to post a comment.

Hi Admin, Seems that the

manurampandit @ 24 Jul 2010 09:54 PM

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

anhdq_adm @ 24 Jul 2010 10:00 PM

@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?

jayeshdhamechai @ 24 Jul 2010 10:15 PM

just one test case?

@jayesh dhamechai: it may

anhdq_adm @ 24 Jul 2010 10:21 PM

@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

jayeshdhamechai @ 24 Jul 2010 10:25 PM

so we need to process input till EOF?

@jayesh dhamechai: oh no,

anhdq_adm @ 24 Jul 2010 10:29 PM

@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

ninjaflyte @ 24 Jul 2010 10:31 PM
Hi, I agree with Manu - the sample test case should have 1 as the answer. "...with the bottom-left corner at (0,0) and top-right corner at (w,h)..." So the matrix looks like this: 0 0 0 4 0 0 0 1 0 0 0 0 2 5 0 0 0 0 0 0 And hence, the best possible case would be to place the center at (1,2). Right?

what does it mean when they

lmconline @ 24 Jul 2010 10:33 PM

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

ninjaflyte @ 24 Jul 2010 10:35 PM

"...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

anhdq_adm @ 24 Jul 2010 10:40 PM

@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

anhdq_adm @ 24 Jul 2010 10:42 PM

@Karthik: (again) please check the problem statement again, you may misunderstand somewhere :-)

how large can the inputs

indraneel @ 24 Jul 2010 10:55 PM

how large can the inputs be?
any ranges?
can we consider all as unsigned integers?

@Indraneel P: please check

anhdq_adm @ 24 Jul 2010 10:58 PM

@Indraneel P: please check the limitations part for details, all are clear ;-)

OOPS........ 2min late to

indraneel @ 25 Jul 2010 12:05 AM

OOPS........

2min late to submit! :(

when will this be posted to

indraneel @ 25 Jul 2010 12:07 AM

when will this be posted to practice problems?
I wan't to check whether my solution is correct.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com