There are t students studying in the best university of Berland. They only study programming in Berland, so there is only one subject. Each student must attend the lectures.
The entire course consists of n lectures. It is known that a student who visits at least k of them will pass the course.
There are only two auditoriums in the university, one has space for a people and the other one — for b people. To make it comfortable, the administration decided that in odd weeks the lectures will be in the first auditorium, and in the even weeks — in the second auditorium. So the first lecture will be in the 1-st auditorium, the second lecture in the 2-nd one, the third in the 1-st one again, and so on.
The sizes of the auditoriums are small so it might not be possible for all students to attend at least k lectures. They ask you to count the maximum number of students that can pass the course.
Input
The first line contains five integers:
t — the number of students;
n — the number of lectures;
a — the size of the first auditorium;
b — the size of the second auditorium;
k — the minimal number of lectures to pass the course.
The limits are: 1 ≤ t, n, a, b, k ≤ 109 .
Output
Print a single integer — the maximal number of students that can attend at least k lectures and thus pass the course.
#include <bits/stdc++.h>
#define INF 0x3fffffff
#define ll long long
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
ll t,n,a,b,k,ans,s;
int main(){
cin >> t >> n >> a >> b >> k;
ll low=0,high=t;
while(low<high){//二分答案
ll mid = (low+high+1)/2;
ll x=min(a,mid), y=min(mid,b);
ll yy,xx;
if(n&1)
yy = n/2, xx = n/2+1;
else
yy = n/2, xx = n/2;
if((x*xx+y*yy)>=k*mid)//k*mid是上课总数,,,x*xx+y*yy是总课数
low=mid;
else
high=mid-1;
}
cout << low << endl;
return 0;
}