• codeforces Gym 100500C D.Hall of Fame 排序


    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
    ",cas,ans);
        }
    }
  • 相关阅读:
    linux安装mongodb数据库./mongod -f mongodb.conf失败或者error
    idea项目提交
    spring5.x日志问题log4j
    IDEA使用apache-tomcat-9.0.16控制台Tomcat日志中文乱码问题
    笔记本网线连服务器内网ip配置
    vue项目启动操作
    win10窗口打开一直处于最小化状态问题
    停止 WinDefend Microsoft Defender Antivirus Service
    关于apt命令和yum命令区别
    20200924-4 代码规范
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4681002.html
Copyright © 2020-2023  润新知