• Codeforces Round #311 (Div. 2) C. Arthur and Table Multiset


    C. Arthur and Table

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/557/problem/C

    Description

    Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.

    In total the table Arthur bought has n legs, the length of the i-th leg is li.

    Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number di — the amount of energy that he spends to remove the i-th leg.

    A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.

    Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought.

    The second line of the input contains a sequence of n integers li (1 ≤ li ≤ 105), where li is equal to the length of the i-th leg of the table.

    The third line of the input contains a sequence of n integers di (1 ≤ di ≤ 200), where di is the number of energy units that Arthur spends on removing the i-th leg off the table.

    Output

    Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.

    Sample Input

    2
    1 5
    3 2

    Sample Output

    2

    HINT

    题意

    桌子有k个桌腿,如果有大于k/2的最长腿的长度相同的话,那么就舒适

    砍掉一个桌腿的代价是d[i],问你最少花费多大的代价,才能得到舒适的桌子

    题解:

    倒着做,依次去掉最长的桌腿,假设有num个

    那么我们只留下num-1个花费最大的腿就好了

    就是这样 喵

    代码

    #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)
    #define maxn 300005
    #define mod 10007
    #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;
    }
    //**************************************************************************************
    
    multiset<int, greater<int> >costs;
    multiset<int>::iterator it;
    vector<int> cost[maxn];
    int l[maxn];
    int main()
    {
        int n=read(),tot=0;
        for(int i=1;i<=n;i++)
            l[i]=read();
        for(int i=1;i<=n;i++)
        {
            int d=read();
            costs.insert(d);
            tot+=d;
            cost[l[i]].push_back(d);
        }
        int ans=tot;
        for(int i=100000;i>=1;i--)
        {
            if(!cost[i].empty())
            {
                for(int j=0;j<cost[i].size();j++)
                {
                    costs.erase(costs.find(cost[i][j]));
                    tot-=cost[i][j];
                }
                int num=0;
                int sum=0;
                for(it=costs.begin();it!=costs.end();it++)
                {
                    if(num==cost[i].size()-1)
                        break;
                    num++;
                    sum+=*it;
                }
                ans=min(ans,tot-sum);
                for(int j=0;j<cost[i].size();j++)
                    tot+=cost[i][j];
            }
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    ELK+Kafka集群日志分析系统
    Centos 6.5 部署 redmine 3.3
    Centos 6.5 搭建l2tp 服务端和客户端
    Logstash之multiline 插件
    MYSQL MHA
    windows上给yii2安装插件
    YII2框架的安装
    Apache服务器配置项和虚拟机配置
    浮点数的比较
    微信自定义菜单总结
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4612221.html
Copyright © 2020-2023  润新知