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

 

转载于:https://www.cnblogs.com/qscqesze/p/4612221.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值