305100: CF965C. Greedy Arkady
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Greedy Arkady
题意翻译
### 题目描述 $k$ 个人想在他们之间分 $n$ 颗糖。每颗糖都应该正好分给其中一个人,否则就扔掉。 这些人的编号从 $1$ 到 $k$,Arkady 是他们中的第一个。为了分割糖果,Arkady 将选择一个整数 $x$,然后把前 $x$ 颗糖果给自己,下一堆 $x$ 颗糖果给第二个人,再下一堆 $x$ 颗糖果给第三个人,如此循环。剩下的部分(不能被 $x$ 整除的剩余部分)将被扔掉。 Arkady 不能选择大于 $M$ 的 $x$,因为这被认为是贪婪的。同时,他也不能选择这么小的 $x$,以至于有些人收到的糖果会超过 $D$ 次,因为这被认为是一种缓慢的分割。 请找出 Arkady 通过选择某个有效的 $x$ 所能得到的最大的糖果数量是多少。 ### 输入格式 唯一的一行包含四个整数 $n,k,M,D$ $(2 \le n \le 10^{18},2 \le k \le n,1 \le M \le n,1 \le D \le \min(1000,n),M \times D \times k \ge n)$,表示糖果的数量,人的数量,一次给一个人的最大糖果数量,一个人可以接受糖果的最大次数。 ### 输出格式 打印一个整数—— Arkady 能给自己的最大可能的糖果数量。 注意,总是可以选择一些有效的 $x$。题目描述
$ k $ people want to split $ n $ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $ 1 $ to $ k $ , and Arkady is the first of them. To split the candies, Arkady will choose an integer $ x $ and then give the first $ x $ candies to himself, the next $ x $ candies to the second person, the next $ x $ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $ x $ ) will be thrown away. Arkady can't choose $ x $ greater than $ M $ as it is considered greedy. Also, he can't choose such a small $ x $ that some person will receive candies more than $ 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 $ .输入输出格式
输入格式
The only line contains four integers $ n $ , $ k $ , $ M $ and $ D $ ( $ 2 \le n \le 10^{18} $ , $ 2 \le k \le n $ , $ 1 \le M \le n $ , $ 1 \le D \le \min{(n, 1000)} $ , $ M \cdot D \cdot k \ge 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.
输出格式
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 $ .
输入输出样例
输入样例 #1
20 4 5 2
输出样例 #1
8
输入样例 #2
30 9 4 1
输出样例 #2
4