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

×

Hungry lemurs hackerearth

Can anyone provide detailed editorial for this problem on hackerearth, hackerearth's tutorial seriously sucks.

In what tag this kind of problems are fond.

Thanks in advance.

asked 24 Jan '16, 11:38

arpit728's gravatar image

1★arpit728
6831462
accept rate: 10%


I would say it would be a ad-hoc/maths problem. The way i solved it is by looping over each possible value of k (all the possible value you could increase/decrease monkeys to) and then finding the closest multiple of this selected number to the given n. Now just find the difference between the actual N and K and the values of n/k you calculated and find minimum. Can be done in O(k) as n,k<=10**5

Here is my submission: http://ideone.com/k7ZoNj (in the loop j denotes k, i denotes n as described above)

link

answered 24 Jan '16, 14:41

vsp4's gravatar image

6★vsp4
1.2k138
accept rate: 28%

edited 24 Jan '16, 14:41

@vsp4 How the solution for the test case 39 16 is 3.

(24 Jan '16, 14:58) arpit7281★

@vsp4

if there are 42 bananas and 16 lemurs then how lemurs would get satisfied.

(24 Jan '16, 15:05) arpit7281★

Damn sorry. It should be 39 16 -> 39 15 -> 39 14 -> 39 13

So 39 % 13 = 0

(24 Jan '16, 15:16) vsp46★

@vsp4

what approach did you use??

(24 Jan '16, 15:47) arpit7281★

@vsp4

why did you start the loop from j=2*k;

(24 Jan '16, 16:13) arpit7281★

@arpit728 Suppose you choose any no l > 2*k Then difference b/w lemurs would be l - k which would atleast be more then (2k - k = k). So it is better to remove all lemurs (that is possible by k moves).

i = n - (n % j);

This finds the greatest multiple of j less or equal to n

then adding +j to that finds least multiple of j more then n.

(24 Jan '16, 17:40) vsp46★
showing 5 of 6 show all

let's take 25 and 7

link

answered 28 Jan '16, 01:55

ankit217's gravatar image

3★ankit217
-22
accept rate: 50%

I dont really see much logic in that solution acording to the themes wordpress of numbers. Parity is never the same.

link

answered 28 Jan '16, 15:53

temarios's gravatar image

0★temarios
14
accept rate: 16%

can you explain your logic in detail?

link

answered 28 Jan '16, 01:54

ankit217's gravatar image

3★ankit217
-22
accept rate: 50%

@ankit217

In your case answer will be 2

8*3=24; 25-1=24;

ans=|8-7|+|25-24|;

Please accept the answer if you understood.

link

answered 29 Jan '16, 07:14

arpit728's gravatar image

1★arpit728
6831462
accept rate: 10%

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:

×15,264
×2,033
×1,643
×1,382
×973
×325
×193

question asked: 24 Jan '16, 11:38

question was seen: 3,444 times

last updated: 29 Jan '16, 07:14