JOINING Editorial


Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Tejas Pandey
Tester: Nishank Suresh, Utkarsh Gupta
Editorialist: Pratiyush Mishra


To be Calculated




N candidates (numbered from 1 to N) join Chef’s firm. The first 5 candidates join on the first day, and then, on every subsequent day, the next 5 candidates join in.
For example, if there are 12 candidates, candidates numbered 1 to 5 will join on day 1, candidates numbered 6 to 10 on day 2 and the remaining 2 candidates will join on day 3.

Candidate numbered K decided to turn down his offer and thus, Chef adjusts the position by shifting up all the higher numbered candidates. This leads to a change in the joining day of some of the candidates.

Help Chef determine the number of candidates who will join on a different day than expected.


Total number of groups of 5 would be:

total = \lfloor \frac{n+4}{5} \rfloor

Total number of groups that won’t be affected:

unaffected = \lfloor \frac{k+4}{5} \rfloor

All the groups that are after the group containing the k_{th} candidate will have 1 person whose joining date will change since he will be shifted to one previous group.

affected = total - unaffected

which is our answer.


O(1), for each test case.


Editorialist’s Solution
Setter’s Solution
Tester1’s Solution
Tester2’s Solution

1 Like