zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    我的书单
    算法面试 字符串全排列
    各种算法面试简介--面试用一句话陈述
    逻辑回归 面试
    EM算法 小结
    python实现 单链表的翻转
    Transformer模型总结
    逻辑回归原理 面试 Logistic Regression
    XGBoost的优点
    python-解决pip安装速度慢的问题--豆瓣镜像
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4612221.html
Copyright © 2011-2022 走看看