C. Greedy Arkady
这题的关键就是算出自己一共receive了多少次,我们可以很容易的便推出这么一个式子—>
(nx+k−1)k
(
n
x
+
k
−
1
)
k
之后嘛暴力二分一下就好啦
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
#include<list>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson root << 1
#define rson root << 1 | 1
ll n,k,m,d;
ll i;
ll cal(ll x)
{
//cout<<111<<endl;
return (n/x+k-1)/k;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>k>>m>>d;
ll ans=0;
for(i=1; i<=d; i++)
{
ll Max=0;
ll l=1,r=m;
while(l<=r)
{
//cout<<111<<endl;
ll mid=l+(r-l)/2;
ll num=cal(mid);
//cout<<111<<endl;
if(num>i)
l=mid+1;
else if(num<i)
r=mid-1;
else
{
Max=i*mid;
l=mid+1;
}
}
ans=max(ans,Max);
}
cout<<ans<<endl;
return 0;
}