Berland University
Time limit1sMemory limit512 MB
Given t students, n lectures alternating between two auditoriums of sizes a and b, and a passing threshold k, find the maximum number of students who can each attend at least k lectures.
- Level
Medium6 of 10
- Topics
- Binary search, Greedy, Math, Implementation
- Solved
- No attempts yet
Statement
There are students at the best university in Berland. They only study programming in Berland, so there is only one subject. Every student must attend the lectures.
The whole course consists of lectures. A student who attends at least of them passes the course.
The university has only two auditoriums, one with space for people and the other for people. To keep things comfortable, the administration decided that in odd weeks the lectures will be in the first auditorium, and in even weeks in the second auditorium. So the first lecture is in auditorium 1, the second lecture in auditorium 2, the third in auditorium 1 again, and so on.
The auditoriums are small, so it may be impossible for all students to attend at least lectures. Find the maximum number of students that can pass the course.
Input
The first line contains five integers:
- --- the number of students;
- --- the number of lectures;
- --- the size of the first auditorium;
- --- the size of the second auditorium;
- --- the minimum number of lectures needed to pass the course.
The limits are .
Output
Print a single integer: the maximum number of students that can attend at least lectures and pass the course.
Hint
In the fourth sample, 5 students can pass the course. One possible strategy is:
- Students , , , , attend the first lecture.
- Students , attend the second lecture.
- Students , , , , attend the third lecture.
- Students , , attend the fourth lecture.
This way each of these 5 students attends at least lectures.