题目链接:http://codeforces.com/problemset/problem/417/A
题目大意:淘汰赛分为主赛和附加赛。每场主淘汰赛的有Ç问题,该轮的获胜者是排名的前n人。每场附加淘汰赛中有d个问题,该轮的获胜者是一个人。此外,K个过去总决赛被邀请的获奖者不需要参加淘汰赛。现在需要选拔出n*m个获胜者,求至少需要准备多少个题目。
题目分析:我是考虑每个题目的价值来比较的,当c/n = d/1时,两者价值相同,最后可能会多出来的单独讨论。
代码参考:
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 2009;
int main()
{
int n, m, c, d, k, cnt;
while (~scanf("%d%d%d%d%d", &c, &d , &n, &m, &k)) {
int tot = max(0, n * m - k);//总共需要选出多少个人
if (c < d * n) {//如果主赛的价值比较大
cnt = (tot / n) * c;//需要的题目数
tot %= n;//剩余的待选人数
} else {//如果附加赛的价值比较大
cnt = tot * d;//需要的题目数
tot = 0;//不会有剩余
}
cnt += min(c, tot * d);//剩下的只可能需要一场比赛就能选出,因此在两场中选所需题目数少的就行了
printf("%d\n", cnt);
}
return 0;
}