#P15040. [UOI 2022 II Stage] 竞赛
[UOI 2022 II Stage] 竞赛
Problem Description
Xonia and her class arrive minutes before the contest starts. Due to epidemic prevention restrictions, the organizers allow students to enter the exam room in groups of every minutes.
In other words, the first group of students will enter the exam room minutes before the contest starts. The next group of students will enter minutes before the start. The next group of students will enter minutes before the start, and so on. Students may even enter at minutes before the start (i.e., at the contest start time). However, students cannot enter after the contest starts.
There are students in total in the class (including Xonia). How many students can enter the exam room before the contest starts?
Input Format
The first line contains four integers , , , ().
Output Format
Output one number —— the number of students who can arrive in time for the contest.
5 2 3 4
4
6 3 2 4
6
10 3 3 6
9
Hint
Sample Explanation
Explanation of the first sample:
- minutes before the start, one group of two students enters the exam room.
- minutes before the start, the remaining three students wait.
- minutes before the start, the remaining three students wait.
- minute before the start, another group of two students enters the exam room.
- minutes before the start, the remaining one student waits. Since time is up, only four students successfully enter.
Explanation of the second sample:
- minutes before the start, one group of three students enters the exam room.
- minutes before the start, the remaining three students wait.
- minutes before the start, another group of three students can enter the exam room. Since there are no more students, all students successfully enter.
Explanation of the third sample:
- minutes before the start, one group of three students enters the exam room.
- minutes before the start, the remaining seven students wait.
- minutes before the start, another group of three students can enter the exam room.
- minute before the start, the remaining four students wait.
- minutes before the start, one group of three students enters the exam room.
- Time runs out, so a total of students enter.
Translated by DeepSeek V3.
Translated by ChatGPT 5