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.
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.
In the first line, print a single integer — the minimum number of problems the jury needs to prepare.
1 10 7 2 1
2
2 2 2 1 2
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;
}