【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C】Greedy Arkady

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

枚举那个人收到了几次糖i. 最好的情况显然是其他人都只收到i-1次糖。 然后这个人刚好多收了一次糖 也即 (i-1)*k*x + x <= n 显然x越大越好。 那么直接令$x=\frac{n}{( (i-1)*k+1)}$就好 如果x>M了 那么令x = M; 但这个时候。 **要判断一下改变之后的x,按照顺序分的时候是否还能满足这个人收到i次糖。** 如果不能收到i次糖的话。跳过。不能统计答案。

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;

const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};

LL n,k,M;
int D;

int main(){
	#ifdef LOCAL_DEFINE
	    freopen("rush_in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(0),cin.tie(0);

	cin >> n >> k >> M >> D;

	long long ans = 0;
	for(LL i = 1;i <= D;i++){
        LL x = n/( (i-1)*k + 1);
        if (x==0) 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<<endl;
	return 0;
}

posted @ 2018-04-26 04:13  AWCXV  阅读(311)  评论(0编辑  收藏  举报