CodeforcesMay 11, 2025

Mister B and Book Reading

Hazrat Ali

Codeforces

At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second — v0 + a pages, at third — v0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v1 pages per day.

Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.

Help Mister B to calculate how many days he needed to finish the book.

Input

First and only line contains five space-separated integers: cv0v1a and l (1 ≤ c ≤ 10000 ≤ l < v0 ≤ v1 ≤ 10000 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.

Output

Print one integer — the number of days Mister B needed to finish the book.

Examples
Input
Copy
5 5 10 5 4
Output
1
Input
12 4 12 4 1
Output
3
Input
15 1 100 0 0
Output
15


Solution

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c, m, l;
  cin >> a >> b >> c >> m >> l;
  int ans = 0, read = 0;
  for (int i = 0; read < a; i++) {
    read = max(0, read - l);
    read += min(c, b + i * m);
    ans++;
  }
  cout << ans << "\n";
  return 0;
}




Comments