codeforces Gym 100500C D.Hall of Fame 排序

本文探讨了在IBM Chill Zone活动中的奖励分配策略。面对只能购买统一尺寸T恤或提供现金的选择,组织者需要最小化支出以确保每位参赛者获得T恤或相应金额。通过排序和线性扫描的方法,实现最优分配方案。

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

Hall of Fame

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100500/attachments

Description

It was the second day of IBM Chill Zone, and it was the time for distributing the prizes. Unfortunately due to unknown reasons, the organizing committee can only buy T-shirts to the contestants or give them D dollars in cash. The T-shirts factory only permitted them to order a single bulk of T-shirts of the same size where a single T-shirt price was determined using this equation: C × S Where C is a given constant, and S is the size of the T-shirt. There was only one limitation on the T-shirts they will give to the contestants, any contestant only accepts to receive a T-shirt of greater or equal size but not smaller size. The organizing committee decided to minimize the money they should pay . Please help them in determining the amount they need to pay in order to give each contestant either a T-shirt or D dollars.

Input

T the number of test cases. For each test case there will be three integers N, D and C , then N integers representing the size of each of the T-shirt of each of the contestants. 1 ≤ T ≤ 100 1 ≤ N ≤ 100, 000 1 ≤ D ≤ 10, 000 1 ≤ C ≤ 10, 000 1 ≤ t − shirtsize ≤ 100, 000

Output

For each test case print a single line containing: Case_x:_y x is the case number starting from 1. y is is the required answer. Replace the underscores with spaces.

Sample Input

1 5 100 1 35 70 75 90 110

Sample Output

Case 1: 425

HINT

 

题意

你可以给人买衣服,也可以给他D元,衣服的价格等于衣服的大小乘以布料钱

求最少给多少钱

题解

排序,然后O(n)扫一遍就好啦~

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=202501;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//*************************************************************************************


ll a[maxn];
int main()
{
    int t=read();
    for(int cas=1;cas<=t;cas++)
    {
        ll n=read(),d=read(),c=read();
        for(int i=1;i<=n;i++)
            a[i]=read();
        sort(a+1,a+n+1);
        ll ans=infll;
        for(int i=1;i<=n;i++)
        {
            ans=min(ans,a[i]*c*(i)+(n-i)*d);
        }
        ans=min(ans,n*d);
        printf("Case %d: %lld\n",cas,ans);
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值