#P15528. [ROIR 2015 Day 2] forest 伐木
[ROIR 2015 Day 2] forest 伐木
Problem Description
Farmer Nikolai hired two lumberjacks, Dmitry and Fyodor, to cut down a forest so that he can plant corn there. There are trees in the forest.
Dmitry cuts down trees per day, but every days he takes a day off and cuts nothing. Therefore, Dmitry rests on days , , , and so on.
Fyodor cuts down trees per day, but every days he takes a day off and cuts nothing. Therefore, Fyodor rests on days , , , and so on.
The two lumberjacks work in parallel. Therefore, on days when neither rests, they cut down trees in total; on days when only Fyodor rests, they cut down trees; on days when only Dmitry rests, they cut down trees; and on days when both rest, they cut down nothing.
Farmer Nikolai wants to know how many days it will take the lumberjacks to cut down all the trees, so that he can start sowing corn.
Task: Write a program that, given integers , , , , and , computes the number of days required for all the trees to be cut down.
Input Format
The input file contains five integers separated by spaces: , , , , and (, , ).
Output Format
The output file should contain one integer — the number of days required to cut down all the trees.
2 4 3 3 25
7
Hint
Example Explanation
In this example, the lumberjacks cut down trees in days, as follows:
- Day : Dmitry cut down trees, Fyodor cut down trees, for a total of trees.
- Day : Dmitry cut down trees, Fyodor cut down trees, for a total of trees.
- Day : Dmitry cut down trees, Fyodor rested, for a total of trees.
- Day : Dmitry rested, Fyodor cut down trees, for a total of trees.
- Day : Dmitry cut down trees, Fyodor cut down trees, for a total of trees.
- Day : Dmitry cut down trees, Fyodor rested, for a total of trees.
- Day : Dmitry cut down trees, Fyodor cut down the remaining tree, for a total of trees cut down.
Scoring System and Subtasks Description
Subtask 1 (32 points)
- , , .
- You can score only if all tests are passed.
Subtask 2 (10 points)
- .
- .
- .
- When solving this subtask, you may assume the lumberjacks do not rest.
- You can score only if all tests are passed.
Subtask 3 (10 points)
- .
- An additional condition is .
- You can score only if all tests are passed.
Subtask 4 (48 points)
- , , .
- This subtask has tests. Each test is worth points, and each test is scored independently.
Translation source: GPT 5.2.
Translated by ChatGPT 5