Problem D. T-shirts (Syria ICPC)

版权声明:版权所有--转载的小伙伴请告知博主并注明来源哦~ https://blog.csdn.net/u011145745/article/details/82054631

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

猜你喜欢

转载自blog.csdn.net/u011145745/article/details/82054631