You are not logged in. Please login at www.codechef.com to post your questions!

×

WA in Cook Off 54 : Abhijeet and rectangles

I understood the editorial to the question but why does my approach not work?

My approach-

Sort the lengths and breadth in two different lists and maintain pointers to the first element of each of them. Let's call these two lists l and b, and the two pointers i and j for our convenience.

Let A1 = l[i] * b[j+1] and A2 = l[i+1] * b[j]

(i.e. A1 = smallest length * second smallest breadth; A2 = second smallest length * smallest breadth)

If A1 < A2 remove the rectangle with shortest length and mark it as removed else remove rectangle with shortest breadth and mark that as removed. My code

Any help will be appreciated!

asked 23 Jan '15, 00:55

vastolorde95's gravatar image

5★vastolorde95 ♦
324
accept rate: 11%

edited 23 Jan '15, 00:59


What answer are you getting for this case... Ans should be 10!!

1
3 2
2 3
3 3
1 10
link

answered 23 Jan '15, 07:27

kunal361's gravatar image

4★kunal361
6.0k133272
accept rate: 21%

I am getting 9, the code removes the wrong rectangle. Got my mistake! Thanks!

(24 Jan '15, 01:45) vastolorde95 ♦5★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,356
×849
×178
×4
×4

question asked: 23 Jan '15, 00:55

question was seen: 1,903 times

last updated: 24 Jan '15, 01:45