博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces Gym 100500C D.Hall of Fame 排序
阅读量:6837 次
发布时间:2019-06-26

本文共 2589 字,大约阅读时间需要 8 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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-9const 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); }}

 

转载地址:http://iyqkl.baihongyu.com/

你可能感兴趣的文章
XJOI网上同步训练DAY2 T2
查看>>
Codeforces 509F Progress Monitoring
查看>>
spring cloud: eureka搭建
查看>>
导弹拦截
查看>>
两个被广泛使用的Model Checking工具
查看>>
BZOJ 4999 This Problem Is Too Simple!
查看>>
POJ - 1995 Raising Modulo Numbers 【快速幂】
查看>>
dwr 文件上传
查看>>
第二章 在HTML中使用JavaScript
查看>>
C++的explicit关键字
查看>>
《SQL Server性能调优实战》知识点汇总
查看>>
JS 中文乱码
查看>>
原生JS实现音乐播放器!
查看>>
hive-安装MySQL(centos6.4)
查看>>
UVa 12100 Printer Queue (习题 5-7)
查看>>
windows下安装apache zookeeper
查看>>
第三周作业
查看>>
git pull --rebase
查看>>
linux下mysql的root密码忘记解决方
查看>>
protobuf 中的嵌套消息的使用 主要对set_allocated_和mutable_的使用
查看>>