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

×

APL3 - Editorial

PROBLEM LINK:

Practice

Contest

DIFFICULTY:

EASY

PREREQUISITES:

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

asked 29 Apr '17, 23:16

accelmage's gravatar image

4★accelmage
52
accept rate: 0%

edited 03 May '17, 13:07

admin's gravatar image

0★admin ♦♦
19.8k350498541


Answer is hidden as author is suspended. Click here to view.

answered 30 Apr '17, 12:57

lucas_dijk's gravatar image

0★lucas_dijk
(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) akshayvenkat975★

Thanks mate!

(30 Apr '17, 13:02) lucas_dijk0★
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,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