×

Practice

Contest

EASY

Math

# EXPLANATION:

The apples can be shared with anyone. Instead of giving an apple to someone only when he needs, we can split the apples equally among all the people at the beginning.

This can be done by finding the total number of apples and dividing by N, to find the average number of apples each person should have.

We do not need the array after this. The average is sufficient to find the solution.

The average can be a floating point value like 2.5, but a person can't have half an apple.

If we find the greatest integer less than or equal to the average (also called as floor), then it gives the day on which the first person dies. eg: floor(2.9)=2

If we find the smallest integer greater than or equal to the average (also called as ceil), then it gives the day on which the last person dies. eg: ceil(2.1)=3

This solution has a complexity of O(n).

# AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.

Tester's solution can be found here.

Both use the same approach.

This question is marked "community wiki".

52
accept rate: 0%

19.8k350498541

 1 Answer is hidden as author is suspended. Click here to view. answered 30 Apr '17, 12:57 (suspended) accept rate: 0% You need to have enough karma points to be able to ask questions on the forum bro. I'll upvote you now, just to make sure you end up having enough. Cheers! (30 Apr '17, 13:01) Thanks mate! (30 Apr '17, 13:02)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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,852
×3,820
×890
×28
×3

question asked: 29 Apr '17, 23:16

question was seen: 494 times

last updated: 03 May '17, 13:07