UpDownHiking
SRM 699 (Cisco) · 2016-08-27 · by Errichto
Problem Statement
During each day of his hike, Limak either ascends or descends. (Each day he has to choose one or the other, he cannot both ascend and descend on the same day.) Additionally, there are two constraints:
- He cannot ascend too quickly, to make acclimatization to higher altitudes easier. More precisely, each day spent ascending can increase his altitude by at most A.
- He cannot descend too quickly, otherwise his knees hurt. More precisely, each day spent descending can decrease his altitude by at most B.
You are given the
Constraints
- N will be between 2 and 50, inclusive.
- A and B will be between 1 and 50, inclusive.
3 7 10 Returns: 10
The highest altitude Limak can reach is 10. Here is one way to do so: On day 1, Limak will start at altitude 0 and he will ascend to altitude 7. On day 2, Limak will start at altitude 7 and he will ascend to altitude 10. On day 3, Limak will start at altitude 10 and he will descend back to altitude 0.
5 40 30 Returns: 80
In the five days of this hike Limak can change his altitude by +40, +40, -27, -27, and -26. The highest altitude reached is 80.
2 50 1 Returns: 1
Even though Limak can climb quickly, moving up even by 50 in one day, he can move down by at most 1 in the second day. So, in the first day he should climb by 1 only.
3 42 42 Returns: 42
20 7 9 Returns: 77
Submissions are judged against all 36 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class UpDownHiking with a public method int maxHeight(int N, int A, int B) · 36 test cases · 2 s / 256 MB per case