PROBLEM LINK:Author: Sergey Kulik DIFFICULTY:Cakewalk PREREQUISITES:Loops, Arrays PROBLEM:There are $N$ students. Only one student can use the dormitory kitchen at at time. The head came up with a timetable for the kitchen's usage to avoid conflicts:
The $i$th student needs $B_i$ units of time to cook. How many students will be able to cook without violating the schedule? EXPLANATION:The $i$th student has at most $A_i  A_{i1}$ units of time to cook, so he/she can cook if and only if $B_i \le A_i  A_{i1}$. So the answer is simply the number of indices $i$ such that $B_i \le A_i  A_{i1}$. For simplicity of implementation, we can just define $A_0 = 0$. The following are implementations in some popular languages. C++:
Java:
Python:
Implementation notes:
Time Complexity:$O(N)$ AUTHOR'S AND TESTER'S SOLUTIONS:
This question is marked "community wiki".
asked 28 May '16, 16:41

I did it by taking another array which stored the differences(memoizing) and achieved a faster running time. answered 31 May '16, 22:18

I compiled successfully and the result is the same as sample testcase.But when I submitted, it's wrong.I dont know why? answered 02 Jun '16, 19:06

@programminghak did u submit the output values after taking all the input values or you submitted them together one by one? answered 03 Jun '16, 15:39

def main(): testCase = input() people = [] timeDict = {} while int(testCase) > len(people): noOfPeople = input() timeOne = input() givenTime = input() timeDict[timeOne] = givenTime people.append(noOfPeople) for el in timeDict: ans = 0 takenTime = el.split() givenTime = timeDict[el].split() for items in takenTime: indx = takenTime.index(items) if indx!= 0: realTime = int(takenTime[indx])  int(takenTime[indx  1])
if name == "main": main() """This has run time error """ answered 22 Jul '16, 09:38

def main(): testCase = input() people = [] timeDict = {} while int(testCase) > len(people): noOfPeople = input() timeOne = input() givenTime = input() timeDict[timeOne] = givenTime people.append(noOfPeople) for el in timeDict: ans = 0 takenTime = el.split() givenTime = timeDict[el].split() for items in takenTime: indx = takenTime.index(items) if indx!= 0: realTime = int(takenTime[indx])  int(takenTime[indx  1])
if name == "main": main() """This has run time error """ answered 22 Jul '16, 09:39

Thnx for the Implementation notes! That's were unknown to me before! Cheers!!! answered 26 Jan '18, 18:49
