codeforces 417A A. Elimination

本文探讨了一种算法问题,即如何通过组织不同类型的选拔赛来确保足够数量的选手进入决赛,同时使得所准备的问题总数尽可能少。文章提供了解决方案,并给出了两种不同的实现代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

根据提供的引用内容,Codeforces Round 511 (Div. 1)是一个比赛的名称。然而,引用内容中没有提供与这个比赛相关的具体信息或问题。因此,我无法回答关于Codeforces Round 511 (Div. 1)的问题。如果您有关于这个比赛的具体问题,请提供更多的信息,我将尽力回答。 #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces Round 867 (Div. 3)(A题到E题)](https://blog.csdn.net/wdgkd/article/details/130370975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值