The kingdom of Lazyland is the home to nn idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland.

Today kk important jobs for the kingdom (k≤nk≤n) should be performed. Every job should be done by one person and every person can do at most one job. The King allowed every idler to choose one job they wanted to do and the ii-th idler has chosen the job aiai.

Unfortunately, some jobs may not be chosen by anyone, so the King has to persuade some idlers to choose another job. The King knows that it takes bibi minutes to persuade the ii-th idler. He asked his minister of labour to calculate the minimum total time he needs to spend persuading the idlers to get all the jobs done. Can you help him?

Input

The first line of the input contains two integers nn and kk (1≤k≤n≤1051≤k≤n≤105) — the number of idlers and the number of jobs.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤k1≤ai≤k) — the jobs chosen by each idler.

The third line of the input contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤1091≤bi≤109) — the time the King needs to spend to persuade the ii-th idler.

Output

The only line of the output should contain one number — the minimum total time the King needs to spend persuading the idlers to get all the jobs done.

Examples

Input

8 7
1 1 3 1 5 3 7 1
5 7 4 8 1 3 5 2

Output

10

Input

3 3
3 1 2
5 3 4

Output

0

Note

In the first example the optimal plan is to persuade idlers 1, 6, and 8 to do jobs 2, 4, and 6.

In the second example each job was chosen by some idler, so there is no need to persuade anyone.

贪心思维题,把劝说时间la[i].a从小到大排序,懒汉工作种类la[i].b,第i个工作有多少懒汉想做k[i]。

最好for循环工作种类,如果第i种工作没人做,从劝说时间最少的懒汉开始扫,如果懒汉数k【i】大于1,则

劝说这个懒汉,扫完即可。

#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
#define maxn 100000+100
typedef long long ll;
struct NODE
{ll a;ll b;
}la[maxn];
ll k[maxn];
bool cmp(NODE a,NODE b)
{return a.a<b.a;
}
int main()
{int n,q;scanf("%d%d",&n,&q);for(int i=1;i<=n;i++){scanf("%lld",&la[i].b);k[la[i].b]++;}for(int i=1;i<=n;i++){scanf("%lld",&la[i].a);}sort(la+1,la+1+n,cmp);
//  for(int i=1;i<=n;i++)
//  printf("%lld+++%lld\n",la[i].a,la[i].b);ll tp=1,ans=0;for(int i=1;i<=q;i++){if(k[i]==0){for(int j=tp;j<=n;j++){if(k[la[j].b]>1){//    cout<<j<<"----"<<la[j].a<<"+++"<<k[la[j].b]<<"+++"<<la[j].b<<endl;k[la[j].b]--;ans+=la[j].a;tp=j+1;break;}}}}printf("%lld\n",ans);return 0;
}

CodeForces - 1089L 贪心相关推荐

  1. 贪心 ---- Codeforces Global Round 8,B. Codeforces Subsequences[贪心,贪的乘法原理]

    题目链接 给出字符串,统计子串(子串字母可以跳跃)是codeforces的数量. 本题要求,给出子串最少数量k,构造字符串s,要求字符串s包含的字母数量最少,输出这个最少的字符串s. 题目要求是至少有 ...

  2. CodeForces - 93B(贪心+vectorpairint,double +double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  3. Codeforces 985C (贪心)

    传送门 题面: C. Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes input ...

  4. Minimize the Permutation CodeForces - 1256(贪心)

    题意: q次询问,每次询问给你长度为n的排列,然后你每次可以选择一个位置i和i+1的数字进行交换.但是每个位置只能交换一次,问你反转若干次后,这个排列最小是多少? 题目: You are given ...

  5. Minimizing Difference CodeForces - 1244E(贪心题)

    题目 题意 官方题解: 百度翻译 思路 ac代码 题意 给出一列数,至多n个操作使其中的数+1或-1,要求得到最小的差值(最大值-最小值): You are given a sequence a1_{ ...

  6. Serval and Parenthesis Sequence CodeForces - 1153C 贪心

    题意:给出一个由"(",")","?"三种字符构成的序列,让我们把其中的问号替换成左右括号,使得整个序列变成一个完整地括号序列,也就是括号匹 ...

  7. Too Many Segments (easy version) CodeForces - 1249D1(贪心+差分)

    题意 给多组线段,而每一个点的覆盖次数不超过K,每次可去除一个线段,问最少去多少线段以及线段的位置. The only difference between easy and hard version ...

  8. Codeforces 360E 贪心 最短路

    题意及思路:https://blog.csdn.net/huanghongxun/article/details/49846927 在假设所有边都是最大值的情况下,如果第一个人能比第二个人先到,那就缩 ...

  9. Codeforces 437D 贪心+并查集

    这个题目让我想起了上次在湘潭赛的那道跪死了的题.也是最值问题,这个也是,有n个动物园 每个都有权值 然后被m条路径相连接,保证图是连通的,然后求所有的p[i][j]之和.i,j为任意两个zoo,pij ...

最新文章

  1. WorldWind Java 版学习:10、服务器响应
  2. 模板 - 数学 - 数论 - 莫比乌斯反演 - 2
  3. 可编程led灯带原理_88张图搞定层板灯带的设计、安装、收口及检修!
  4. 随笔分类 - java高级特性
  5. linux fb应用例子,Linux下利用framebuffer画点的程序小例子
  6. 【C语言】一元二次方程(求实根和虚根)
  7. dm8148 开发之---4路解码器tvp5158
  8. ESXI 带网卡realtek驱动下载
  9. 摄像机和镜头的基础知识
  10. TCP连接的四次挥手全过程
  11. 达人评测 华为MatePad2和华为MatePad2 Pro 怎么样
  12. Oracle错误12154的解决方法
  13. 关于Http请求GBK乱码转化的问题
  14. 【音视频处理】码率、帧率越高越清晰?分辨率、像素、dpi之间是什么关系?码率的真实作用,I帧、B帧、P帧是什么
  15. Launcher3-桌面布局+主要的类+启动流程
  16. 八位计算机最小二进制,八位二进制补码最小值
  17. 小程序项目:微信小程序美容理发店预约系统app——计算机毕业设计
  18. 倚杖听江声夜雨剪春韭
  19. 独立app开发和运行(使用篇)
  20. python 爬虫-爬取学堂在线合作院校

热门文章

  1. android蓝牙获取mac地址,如何获得蓝牙连接设备的MAC地址在android中
  2. redis-JedisPoolConfig配置
  3. Java大数据:大数据开发必须掌握的四种数据库
  4. 火力全开2不显示服务器,火力全开2搜不到服务器怎么办 需要root吗
  5. 【前端库】typed.js 打字机效果
  6. android版本不一样可以刷机嘛,安卓手机怎么刷系统?不用软件直接刷手机系统图解...
  7. javaScript 正则表达式总结
  8. 代码验证约瑟夫环百科词条中的故事(Python)——约瑟夫斯的故事、数学家加帕斯讲的故事,体验算法模板的奇妙。
  9. 基于若依框架的Java项目-尚医疗(医疗管理项目)
  10. 基于java的敬老院养老院管理系统