Codeforces Gym 100500C D.hall of Fame sort

Source: Internet
Author: User
Tags cas

Hall of Fame

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

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

Description

It is the second day of the IBM Chill Zone, and it is 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 dol Lars 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:cxs Where C are a given constant, and S is the size of the T-shirt. There is only one limitation on the T-shirts they would 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 on order to give each contestant either a T-shirt or D dollars .

Input

T the number of test cases. For all test case there is 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 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

Test instructions

You can buy clothes, you can give him D-yuan, the price of clothes is equal to the size of clothes multiplied by the cloth money

Ask for at least how much money

The following:

Sort, and then O (n) sweep it all over again ~

Code

#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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************ll A[MAXN];intMain () {intt=read ();  for(intcas=1; cas<=t;cas++) {ll n=read (), D=read (), c=read ();  for(intI=1; i<=n;i++) A[i]=read (); Sort (a+1, a+n+1); ll ans=infll;  for(intI=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); }}

Codeforces Gym 100500C D.hall of Fame sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.