PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Setter: Hasan
Tester: Teja Vardhan Reddy
Editorialist: Taranpreet Singh
DIFFICULTY:
Cakewalk
PREREQUISITES:
None at all (what did you expect?? :D)
PROBLEM:
Given N submission’s starting time S_i and ending time J_i, we need to count number of submissions which have delay of more than 5 minutes.
SUPER QUICK EXPLANATION
-
Answer is number of submissions for which $J_i - S_i >5$ holds.
EXPLANATION
When trying to solve a problem, the most basic intuition we need to have is that can we simulate the whole process without getting Wrong answer of Time Limit Exceeded. If answer is yes, we can just Simulate the whole process without wasting time, and find out answer.
In this problem, we can, for every submission, calculate the expected time, so that if submission is judge after this expected time, Submission is delayed.
Expected ending time is same as Actual Starting time + Expected judging time (given 5 minutes in this problem).
So, our final solution becomes, iterate over every submission, see if Actual ending time is later than Expected judging time.If yes, increase answer by 1. Print the final answer.
This is it. You may feel free to refer Solutions if you wish to.
Time Complexity
Since we iterate over all customers only once, Time complexity is O(N).
AUTHOR’S AND TESTER’S SOLUTIONS:
Setter’s solution
Tester’s solution
Editorialist’s solution
Edit: Until above links are not working, feel free to refer solution here.
Feel free to Share your approach, If it differs. Suggestions are always welcomed.