AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

FPC25-029.Hopelessly Hungover

Easy · 1 s · 256 MB

  • icpc
  • fpc
  • 2025

First-year student Bob needs to learn nnn 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 nnn facts to pass.

On weekdays, Bob studies diligently and can learn at most kkk facts per day. On weekends, there are the Freshmen Party Committee events, meticulously planned and impossible to miss, where he forgets mmm facts per day due to sheer excitement. Of course, when the number of facts Bob knows is less than mmm, 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 nnn facts, or determine that he never learns all nnn facts.

As an example, consider the first sample input, where Bob needs to learn 141414 facts. He can learn 111 fact every weekday and forgets 111 fact per day in the weekend. He starts off knowing 000 facts on a Monday morning. Bob learns 111 fact during the day. He does so on all the 555 weekdays, so on Saturday morning he knows 555 facts. Unfortunately, he forgets a fact on both Saturday and Sunday, so he starts the second week on Monday morning knowing 333 facts. This keeps going in the span of 444 weeks. On the Friday of the last week, he knows all the 141414 facts so he can start his online exam in the evening. This turns out to be exactly 262626 days, accounting for the starting Monday and final Friday as well.

Giriş formatı

The input consists of:

• One line with four integers nnn, kkk, mmm, and ddd (1≤n,k,m≤10001 \leq n,k,m \leq 10001≤n,k,m≤1000, 1≤d≤71 \leq d \leq 71≤d≤7), where: nnn is the total number of facts that Bob must learn, kkk is the number of facts learned on a weekday, mmm is the number of facts forgotten on a weekend day, and ddd represents the current day of the week (where 111 corresponds to Monday and 777 corresponds to Sunday).

Çıxış formatı

Output the number of days (including the current day) that elapse before Bob first knows all nnn 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