• 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);
        }
    }
  • 相关阅读:
    不开心的事
    git push 时 error: RPC failed; HTTP 400 curl 55 Send failure: Connection was reset 问题
    Java多线程相关
    angularJS 级联下拉框
    leetcode260 Single Number III
    -2147483648的绝对值
    git 提交信息模板
    rabbitmq at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-5.4.3.jar:5.4.3] 错误
    Unity 切换场景的注意点
    Java位运算
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4681002.html
Copyright © 2020-2023  润新知