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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';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=;
for(int i=;i<=n;i++)
l[i]=read();
for(int i=;i<=n;i++)
{
int d=read();
costs.insert(d);
tot+=d;
cost[l[i]].push_back(d);
}
int ans=tot;
for(int i=;i>=;i--)
{
if(!cost[i].empty())
{
for(int j=;j<cost[i].size();j++)
{
costs.erase(costs.find(cost[i][j]));
tot-=cost[i][j];
}
int num=;
int sum=;
for(it=costs.begin();it!=costs.end();it++)
{
if(num==cost[i].size()-)
break;
num++;
sum+=*it;
}
ans=min(ans,tot-sum);
for(int j=;j<cost[i].size();j++)
tot+=cost[i][j];
}
}
cout<<ans<<endl;
}

Codeforces Round #311 (Div. 2) C. Arthur and Table Multiset的更多相关文章

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

    C. Arthur and Table time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  3. BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls

    题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...

  4. 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table

    题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  5. C. Arthur and Table(Codeforces Round #311 (Div. 2) 贪心)

    C. Arthur and Table time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #311 (Div. 2)

    我仅仅想说还好我没有放弃,还好我坚持下来了. 最终变成蓝名了,或许这对非常多人来说并不算什么.可是对于一个打了这么多场才好不easy加分的人来说,我真的有点激动. 心脏的难受或许有点是由于晚上做题时太 ...

  7. Codeforces Round #311 (Div. 2) A,B,C,D,E

    A. Ilya and Diplomas 思路:水题了, 随随便便枚举一下,分情况讨论一下就OK了. code: #include <stdio.h> #include <stdli ...

  8. Codeforces Round #311 (Div. 2)题解

    A. Ilya and Diplomas time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #297 (Div. 2) D. Arthur and Walls [ 思维 + bfs ]

    传送门 D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input stan ...

随机推荐

  1. 我常用的VBS方法(QTP)

    这些是4年前在HP用QTP做自动化测试时候总结的一些,现在贴出来,说不准以后会不会用到 当初花了2天时间写的一个自动生成的Excel Report Public Function Report (st ...

  2. C++C#时间转换

    time_t是从1970年1月1日的格林尼治时间开始的,所以以下就是你要的结果System.DateTime time= new System.DateTime(1970, 1, 1).ToLocal ...

  3. 使用U盘安装win7系统,遇到“无法定位现有系统分区”问题

    朋友的本子貌似因为安装360wifi而导致一进入系统就蓝屏重启,虽然之后就卸载了360wifi,但是问题依旧,上网Google了一下,发觉网上不少网友诉苦,也有人分析原因,说是因为360wifi导致了 ...

  4. String内存陷阱简介

    String 方法用于文本分析及大量字符串处理时会对内存性能造成一些影响.可能导致内存占用太大甚至OOM. 一.先介绍一下String对象的内存占用 一般而言,Java 对象在虚拟机的结构如下:•对象 ...

  5. iframe和frame的区别

    在同时有frame和Iframe的一个窗口里frame最大可以做个frameset的儿子,Iframe最大也只能做到frameset的孙子.frame的布局限于几种,Iframe想放哪里放哪里.fra ...

  6. KM算法详解+模板

    http://www.cnblogs.com/wenruo/p/5264235.html KM算法用来求二分图最大权完美匹配. 本文配合该博文服用更佳:趣写算法系列之--匈牙利算法 现在有N男N女,男 ...

  7. 第三百三十九天 how can I 坚持

    脑子里老是无缘无故浮现出之前学的古文,之前只是傻学了,什么都没搞懂啊. 吾师道也,夫庸知其年之先后生于吾乎?是故无贵无贱,无长无少,道之所存,师之所存也. 是故弟子不必不如师,师不必贤于弟子,闻道有先 ...

  8. MyEclipse中消除frame引起的“the file XXX can not be found.Please check the location and try again.”的错误

    读者如要转载,请标明出处和作者名,谢谢. 地址01:http://space.itpub.net/25851087 地址02:http://www.cnblogs.com/zjrodger/ 作者名: ...

  9. HD2086A1 = ?

    Problem Description 有如下方程:Ai = (Ai-1 + Ai+1)/2 - Ci (i = 1, 2, 3, .... n). 若给出A0, An+1, 和 C1, C2, .. ...

  10. 解决 Unable to load DLL 'OraOps9.dll': 找不到指定的模块。 (Exception from HRESULT: 0x8007007E)

    这个问题网上的答案是把oracle的home文件夹权限变为完全控制,然而并没有好用,还有一种方法是在编写的程序的config文件加入 <runtime> <legacyCorrupt ...