#B3923. Problem: Exam Problem Count with Early Stop
Problem: Exam Problem Count with Early Stop
Problem: Exam Problem Count with Early Stop
Little Yang is preparing for an exam by practicing problems every day. On day \(1\), he solves \(a\) problems, and on day \(2\), he solves \(b\) problems. From day \(3\) onwards, the number of problems he solves each day is the sum of the problems solved in the previous two days, i.e., for \(n \ge 3\):
\(T(n) = T(n-1) + T(n-2)\)
However, Little Yang has a rule: if on any day he solves \(m\) or more problems, then for every subsequent day he solves 0 problems. Note that the day on which the rule is triggered is counted normally.
Your task is to determine the total number of problems he has solved by day \(N\).
inputFormat
The input consists of four space-separated integers: \(a\), \(b\), \(m\), \(N\), where:
- \(a\) (\(1^{st}\) day's problems)
- \(b\) (\(2^{nd}\) day's problems)
- \(m\): the threshold that if reached or exceeded on a day, stops subsequent practice
- \(N\): the total number of days
outputFormat
Output a single integer representing the total number of problems solved by day \(N\).
sample
1 2 10 5
19