Problem D. T-shirts (Syria ICPC)

Problem D. T-shirts

来源:ACM International Collegiate Programming Contest, Syrian Collegiate Programming Contest (2014) Syria, September, 23, 2014  CF链接Gym 100500D

Problem 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

Examples

Tshirts.in

1

5 100 1

35

70

75

90

110

Standard Output

Case 1: 425

Note

The optimal solution is to buy 3 tshirts of size 75 for the first 3 contestants, and give 100 dollars to the last two.

题目应该不难,但是数据处理需要注意。

代码如下:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    int t,a[100010],i,n,d,c,k=0;
    scanf("%d",&t);
    while(t--)
    {
        k++;
        scanf("%d%d%d",&n,&d,&c);
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a+1,a+n+1);
        long long sum=(long long)d*n; // 注意使用long long
        for(i=1;i<=n;i++)
        {
            sum=min(sum,(long long)a[i]*c*i+(long long)(n-i)*d);
 
        }
        printf("Case %d: %lld\n",k,sum);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WMYBlog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值