PROBLEM LINK:Author: Sidhant Bansal DIFFICULTY:easy PREREQUISITES:basic math PROBLEM:In this problem, the greedy approach of buying the box of chocolate for some consecutive early days is the right direction. Let $A = K * S$ and $B = N * (S  S/7)$, here $A$ denotes the total number of chocolates we need to eat and $B$ denotes the maximum no. of chocolates we can buy. Here $S  S/7$ denotes the number of days the shop is open. So if $A > B$ or ($(N  K) * 6 < K$ and $S \geq 7$), then the answer is $1$. otherwise the answer is ceil($\frac{A}{N}$), where ceil($x$) denotes ceiling function on $x$. The first condition i.e $A > B$, for $1$ is fairly obvious that if the total no. of chocolates we need to eat is more than we can buy at max then it is invalid. The second condition i.e $(N  K) * 6 < K$ and $S \geq 7$ is a bit tricky, it is basically the contrapositive of the statement, "if you can survive the first $7$ days, then you can survive any given number of days". So the contrapositive (i.e same statement in different words) is "if you cannot survive the first $7$ days then you won't be able to survive for $S \geq 7$". The condition for being able to survive on the $7^{th}$ day is basically if we add our remaining chocolates from the first 6 days, i.e $(N  K) * 6$ and it is still smaller than $K$, i.e the chocolates we need for the $7^{th}$ day, then we don't survive. But we only need to test this when $S \geq 7$. Incase, we are able to survive, then the answer is ceil($\frac{A}{N}$), which is basically total number of chocolates we need to eat divided by the number of chocolates we can buy in a single day (and if a remainder exists, then we need to buy one more day). This portion is pretty straightforward. The above reasoning to check for $1$ is obviously tricky and a simpler approach exists which is to just simulate the days once we know the value of ceil($\frac{A}{N}$). SOLUTIONS
This question is marked "community wiki".
asked 21 Jan '18, 23:50

@admin Weak test cases for this question: Submissions giving wrong answer I request you to add this test case in practice question. Please make sure such things not happen in future as it brings down the moral of participants. answered 22 Jan '18, 10:31
Please add this at least to practice test cases
(19 Feb '18, 17:04)
Another Weak Testcase
(19 Feb '18, 17:07)

@admin The test cases are very week 1 8 7 8. The output should be 1. But many accepted solutions of this problem are producing output 7 for this case which is quite obvious wrong. Please make sure such kind of things not occur in future and the test cases for questions in the contest should have appropriate corner cases. answered 22 Jan '18, 16:31

For the first condition we could just use $N < K$ (we must buy at least a day supply of chocolate on the first day), and the second condition can be written as $6N < 7K$ (we must buy at least a week supply of chocolate during the first week). answered 22 Jan '18, 10:38

Problem: SURVIVE My short solution in PYTHON3.5:My solution in O(n) easy to understand. O(1) is more efficient
LOGIC: Maxmimum choclates he needs is ks which is capacity. And the availablity of chocolates is ns(n(s//7)) as on Sunday shop is closed and he can't buy any chocolates. So if capacity > availablity print("1") as it is not possible to purchase. Else Run a loop to find the number of days and dont forget not to calculate sundays and add n chocolates only on non sundays. Like,Comment, Follow and award reputation points if u like. For any other queries or doubts contact me. For Codes as files to download visit: DOWNLOAD CODE answered 22 Jan '18, 18:10

What seems wrong with my code?answered 04 Aug '18, 13:44

include <iostream>using namespace std; int main() {
}
link
This answer is marked "community wiki".
answered 15 Aug '18, 01:32

answered 05 Oct '18, 00:05

1 30 6 30 check this one correct answer should be 1 but many accepted solutions are showing it to be 6.please anyone help!! answered 21 Dec '18, 15:23

1 30 6 30 check this one correct answer should be 1 but many accepted solutions are showing it to be 6.please anyone help!! answered 21 Dec '18, 15:23
