n candies between them. Each candy should be given to exactly one of them or be thrown away.

The people are numbered from x) will be thrown away.

Arkady can't choose D times, as it is considered a slow splitting.

Please find what is the maximum number of candies Arkady can receive by choosing some valid x.

Input

The only line contains four integers M⋅D⋅k≥n) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.

Output

Print a single integer — the maximum possible number of candies Arkady can give to himself.

Note that it is always possible to choose some valid x.

Examples
input
Copy
20 4 5 2
output
Copy
8
input
Copy
30 9 4 1
output
Copy
4
Note

In the first example Arkady should choose 8 candies in total.

Note that if Arkady chooses 2 times.

In the second example Arkady has to choose 1 time.

 

 

数学题,d比较小,枚举d

贪心思考,最好应该是第一个人取i次,其他人取i-1次 

x*i+x*(i-1)*(k-1)<=n

若x>m 取x=m 然后重新判断是否可以到 i 组

 

//#include <bits/stdc++.h>
#include<iostream>
#include<stack>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
    return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
    return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
    return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
    return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (ll i = (a); i <= (b); i++)
#define FFor(i, a, b) for (int i = a; i >= (b); i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N = 2000;
const int M=200005;
// name*******************************
ll n,k,m,d;
ll t;
ll ans=0;
// function******************************

//***************************************
int main()
{
    //    ios::sync_with_stdio(0);
    //    cin.tie(0);
    //     freopen("test.txt", "r", stdin);
    //  freopen("outout.txt","w",stdout);
    cin>>n>>k>>m>>d;
    For(i,1,d)
    {
        ll x=n/((i-1)*k+1);
        if(!x)break;
        if(x>m)x=m;
        if(n/(k*x)+((n%(k*x)>=x)?1:0)!=i)continue;
        ans=max(ans,x*i);
    }
    cout<<ans;
    return 0;
}

 

相关文章: