您的位置:首页 > 其它

codeforces 417A A. Elimination

2017-08-18 18:43 267 查看
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 i
4000n 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.

Examples

input
1 10
7 2
1


output
2


input
2 22 1
2


output
0

题意:最终的比赛需要有n*m个队伍参加,有保送的k个队伍,有主选拔方式需要出c个问题,选出n个队伍,有次选拔方式,出d个问题,选拔一个人。求最少需要出几个问题。

思路比较两种方式的价值,其实是一个简单的完全背包,但是比赛的时候一直没有写对。其实不用背包写,也是很简单的一个问题。
主形式选拔方式:c个问题,n个人
次选拔方式:d个问题,1个人
所以可以得出用次形式选拔n个人需要n*d个问题,所以只需要比较c和n*d,选择比较小的一个。
最后的细节需要处理一下。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define N 2005

using namespace std;

int c,d,n,m,k;

int main()
{
scanf("%d %d %d %d %d",&c,&d,&n,&m,&k);
int sum;
sum=n*m-k;
if(sum<=0){
printf("0\n");
return 0;
}
int ans;
int t=sum/n;
int aa=sum%n;
ans=t*min(c,n*d)+min(aa*d,c);
printf("%d\n",ans);
return 0;
}


在下边再贴上一种背包的代码。
#include <cstdio>
#include <cstring>
#define inf 0x3f3f3f3f
#define N 10005
int f
,c,d,n,m,k;
inline int min(int x,int y){return x<y?x:y;}

int main()
{
scanf("%d %d %d %d %d",&c,&d,&n,&m,&k);
if(n*m<=k){puts("0");return 0;}
memset(f,inf,sizeof(f));f[0]=0;
for(int i=1;i<=n*m;++i){
if(i>=n) f[i]=f[i-n]+c;
f[i]=min(f[i],f[i-1]+d);
}
for(int i=1;i<=n*m;i++)
{
printf("%d ",f[i]);
}
printf("\n");
int ans=inf;
for(int i=n*m-k;i<=n*m;++i)
if(f[i]<ans) ans=f[i];
printf("%d\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: