Elimination(数学)

A. Elimination
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.

The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination.

As a result of all elimination rounds at least n·m people should go to the finals. You need to organize elimination rounds in such a way, that at least n·m people go to the finals, and the total amount of used problems in all rounds is as small as possible.

Input

The first line contains two integers c and d (1 ≤ c, d ≤ 100) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≤ n, m ≤ 100). Finally, the third line contains an integer k (1 ≤ k ≤ 100) — the number of the pre-chosen winners.

Output

In the first line, print a single integer — the minimum number of problems the jury needs to prepare.

Sample test(s)
input
1 10
7 2
1
output
2
input
2 2
2 1
2
output
0

 

       题意:

       选择赛制挑选人进 Final,有两种赛制。第一种是共有 c 个题目可以一次性挑选出前面的 n 人,第二种是共有 d 个题目每次可以挑选出 1 人,Final 需要有 n * m 的人参赛,其中有 k 个人是不需要通过选拔就能参加 Final 的。问如何选择赛制使出的题目数最少。

 

       思路:

       数学。若 n * m - k <= 0 则说明不需要选择题目,输出0。否则,则需要另外挑选 n * m - k 人。那么选择赛制有三种情况,只需要选 第一种赛制,只需要选第二种赛制,或者两种的结合。

       求出 left / n,代表最多能选择 cm 场第一赛制的,并且算出 left % n,代表剩下的人不能凑够第一赛制选拔的人数 ca,则可能这些人要选择第二种赛制。

       故可得出两部分比较值(cm代表场数,ca代表人数):

       sum += min (cm * c,cm * n * d),cm * c 代表第一场需要的题目数;cm * n * d 代表第二场需要的题目数,cm * n 代表人数;

       sum += min (c,ca * d),剩下的人只需要一场第一种赛制的,故 c 代表第一场题目数;ca * d 代表选择第二场的题目数。最后 sum 值即为所需的题目最小值。

 

       AC:

#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
        int c, d, n, m ,k;
        int l;
        scanf("%d%d%d%d%d", &c, &d, &n, &m, &k);
        l = n * m - k;
        if (l <= 0) puts("0");
        else {
                int cm = l / n, ca = l % n;
                int sum = 0;
                sum += min(cm * c, cm * n * d);
                sum += min(c, ca * d);
                printf("%d\n", sum);
        }
        return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值