codeforces 417A A. 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.

Examples
input
1 10
7 2
1
output
2
input
2 2
2 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[N],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;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值