Stars on Shoulder Boards
Time limit2sMemory limit512 MB
Given bounds on star counts and the min and max stars removable from officer Y, find the smallest and largest possible battalion size.
- Level
Medium5 of 10
- Topics
- Math, Implementation, Brute force, Intervals
- Solved
- No attempts yet
Problem
In a battalion of unclear purpose, a rule holds that every officer must have at least and at most stars on his shoulder boards, and no two officers may have the same number of stars.
As a result of a demotion, an officer Й was transferred to this battalion. Before the demotion, officer Й had stars on his shoulder boards. The battalion commander must now remove some of the stars from Й's shoulder boards, so that the number of stars on them becomes strictly less than .
The battalion commander looked into the matter and found that the smallest positive number of stars that can be removed from officer Й's shoulder boards so that the rule holds is , and the largest is . The commander immediately reported this to officer Й.
Officer Й now wonders: what is the smallest and the largest number of officers that could have been in the battalion before his arrival? The battalion commander is not an officer of the battalion, and his shoulder boards bear special mysterious symbols instead of stars.
Input
The first line contains five integers , , , , (, , , ).
The situation is guaranteed to be consistent: officer Й can be demoted so that the rule stated in the problem holds, and the commander's statement is true.
Output
Output the smallest and the largest possible number of officers in the battalion.