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. 华为鸿蒙系统6月24首发,华为终于迎来好消息,P50系列有望在6月上市,首发搭载鸿蒙OS系统...
  2. 计算机与十进制 教案,二进制与十进制间的转换教案
  3. SQL FOREIGN KEY 约束
  4. Hibernate优化策略
  5. 1339: 考试排名
  6. Linux 下的复制命令,这几个比较靠谱
  7. 计算机网络之数据链路层:7、选择重传协议(SR)
  8. CF刷刷水题找自信 2
  9. Redis 最大连接数查询与设置、释放超时链接
  10. 数据分析:星巴克店铺分布有何规律?
  11. Exchange 2010 UM角色安装后无法启动服务,错误 1000,1001
  12. 基于汽车运动学模型的LQR控制
  13. Windows Azure AppFabric (一) 平台简介
  14. cachecloud部署和创建机器
  15. wamp php 如何安装,WAMP的详细安装过程分享
  16. ICPC训练联盟2021寒假冬令营(6)_2021.01.25_笔记
  17. 谷歌浏览器Google如何设置站点弹出窗口
  18. 10.12-长沙亚信面试内容
  19. 微信打开页面,下载东西时调用其他浏览器下载
  20. error LNK2019: 无法解析的外部符号 _Direct3DCreate9@4,该符号在函数 long __cdecl InitD3D(struct HWND__ *) (?InitD3D

热门文章

  1. 华为linux系统还原,使用再生龙(clonezilla)制作系统还原盘并恢复还原
  2. 软件工程理论与实践学习——炸鸡的读后感
  3. MAXTHON浏览器给CSDN博客带来的小麻烦!
  4. 雪城大学信息安全讲义 3.4 最小权限原则
  5. 《大卫·奥格威自传》听书笔记
  6. elementUI 表格多选框this.$refs.xxx.toggleRowSelection无效
  7. NGUI 3.0.7的新锚点系统设置不好就会造成显示错误的错觉
  8. 中国移动一键登录 —— Flutter(安卓)
  9. python 股票数据爬取(两种方法)
  10. C# 事件中委托方法的Lambda简洁写法用及作用域