CF965C.Greedy Arkady

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

kk people want to split nn candies between them. Each candy should be given to exactly one of them or be thrown away.

The people are numbered from 11 to kk, and Arkady is the first of them. To split the candies, Arkady will choose an integer xx and then give the first xx candies to himself, the next xx candies to the second person, the next xx candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by xx) will be thrown away.

Arkady can't choose xx greater than MM as it is considered greedy. Also, he can't choose such a small xx that some person will receive candies more than DD times, as it is considered a slow splitting.

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

kk 个人希望将 nn 颗糖果在他们之间分配。每颗糖果必须恰好分给其中一人,或被丢弃。

这些人编号为 11 到 kk,Arkady 是第一个人。为了分配糖果,Arkady 将选择一个整数 xx,然后将前 xx 颗糖果分给自己,接下来的 xx 颗糖果分给第二个人,再接下来的 xx 颗糖果分给第三个人,依此类推,按顺序循环进行。剩余的(即不能被 xx 整除的部分)糖果将被丢弃。

Arkady 不能选择大于 MM 的 xx,因为这被视为贪婪行为。此外,他也不能选择过小的 xx,使得某个人获得糖果的次数超过 DD 次,因为这被视为分配过程过于缓慢。

请找出 Arkady 在选择某个合法的 xx 时,最多能获得多少颗糖果。

输入格式

The only line contains four integers nn, kk, MM and DD (2≤n≤10182 \le n \le 10^{18}, 2≤k≤n2 \le k \le n, 1≤M≤n1 \le M \le n, 1≤D≤min⁡(n,1000)1 \le D \le \min{(n, 1000)}, M⋅D⋅k≥nM \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.

唯一一行包含四个整数 nn、kk、MM 和 DD(2≤n≤10182 \le n \le 10^{18},2≤k≤n2 \le k \le n,1≤M≤n1 \le M \le n,1≤D≤min⁡(n,1000)1 \le D \le \min{(n, 1000)},且满足 M⋅D⋅k≥nM \cdot D \cdot k \ge n)——分别表示糖果总数、人数、单次最多分给一个人的糖果数、一个人最多能领糖果的次数。

输出格式

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 xx.

输出一个整数——Arkady 能够给自己的糖果的最大可能数量。

注意:总可以选出某个合法的 xx。

输入输出样例

  • 输入#1

    20 4 5 2

    输出#1

    8
  • 输入#2

    30 9 4 1

    输出#2

    4

说明/提示

In the first example Arkady should choose x=4x = 4. He will give 44 candies to himself, 44 candies to the second person, 44 candies to the third person, then 44 candies to the fourth person and then again 44 candies to himself. No person is given candies more than 22 times, and Arkady receives 88 candies in total.

Note that if Arkady chooses x=5x = 5, he will receive only 55 candies, and if he chooses x=3x = 3, he will receive only 3+3=63 + 3 = 6 candies as well as the second person, the third and the fourth persons will receive 33 candies, and 22 candies will be thrown away. He can't choose x=1x = 1 nor x=2x = 2 because in these cases he will receive candies more than 22 times.

In the second example Arkady has to choose x=4x = 4, because any smaller value leads to him receiving candies more than 11 time.

在第一个例子中,阿尔卡季应选择 x=4x = 4。他将给自己分发 44 颗糖果,给第二个人分发 44 颗糖果,给第三个人分发 44 颗糖果,再给第四个人分发 44 颗糖果,然后再次给自己分发 44 颗糖果。没有任何人被分发糖果超过 22 次,而阿尔卡季总共获得 88 颗糖果。

注意,若阿尔卡季选择 x=5x = 5,他仅能获得 55 颗糖果;若他选择 x=3x = 3,他将获得 3+3=63 + 3 = 6 颗糖果,同时第二、第三和第四个人各获得 33 颗糖果,剩余 22 颗糖果被丢弃。他不能选择 x=1x = 1 或 x=2x = 2,因为在这些情况下,他将被分发糖果超过 22 次。

在第二个例子中,阿尔卡季必须选择 x=4x = 4,因为任何更小的值都会导致他被分发糖果超过 11 次。

输入解题思路,AI测评打分。不知道怎么写?

首页