FPC25-029.Hopelessly Hungover
Easy · 1 s · 256 MB
- icpc
- fpc
- 2025
First-year student Bob needs to learn facts for an online exam. Currently, he knows none. The exam can be taken at any time, even during weekends, but due to the surveillance software, it is impossible to cheat. The grading is quite harsh and requires that he knows all the facts to pass.
On weekdays, Bob studies diligently and can learn at most facts per day. On weekends, there are the Freshmen Party Committee events, meticulously planned and impossible to miss, where he forgets facts per day due to sheer excitement. Of course, when the number of facts Bob knows is less than , he will forget all the facts during the party and wakes up the next day knowing none. Starting in the morning of some given day of the week, determine how many days it takes until he first knows all facts, or determine that he never learns all facts.
As an example, consider the first sample input, where Bob needs to learn facts. He can learn fact every weekday and forgets fact per day in the weekend. He starts off knowing facts on a Monday morning. Bob learns fact during the day. He does so on all the weekdays, so on Saturday morning he knows facts. Unfortunately, he forgets a fact on both Saturday and Sunday, so he starts the second week on Monday morning knowing facts. This keeps going in the span of weeks. On the Friday of the last week, he knows all the facts so he can start his online exam in the evening. This turns out to be exactly days, accounting for the starting Monday and final Friday as well.
Giriş formatı
The input consists of:
• One line with four integers , , , and (, ), where: is the total number of facts that Bob must learn, is the number of facts learned on a weekday, is the number of facts forgotten on a weekend day, and represents the current day of the week (where corresponds to Monday and corresponds to Sunday).
Çıxış formatı
Output the number of days (including the current day) that elapse before Bob first knows all facts. Note that the last day that Bob still needs to study should be included, although he will know all the facts on the same day in the evening and can start his exam immediately. If Bob can never learn all facts, output “impossible”.
Qeyd
Source: Freshmen Programming Contest 2025 · License: CC BY-SA 4.0 · Original: https://fpc.wisv.ch · Statement adapted for AlgoLens and shared under the same license.
Nümunələr
Giriş #1
14 1 1 1
Çıxış #1
26
Giriş #2
15 1 10 4
Çıxış #2
impossible
Giriş #3
10 2 20 2
Çıxış #3
11