C. Dishonest Sellers
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi.

Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.

Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items.

Input

In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now.

The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now).

The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week).

Output

Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.

Examples
input
3 1
5 4 6
3 1 5
output
10
input
5 3
3 4 7 10 3
4 5 5 12 5
output
25
Note

In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.

In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.

思路;

  计算价值然后排序水过(至少k个不是共k个);

来,上代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> #define maxn 200005 using namespace std; struct SortNodeType {
int ai,bi,vi;
};
struct SortNodeType item[maxn]; int if_z,n,k,ans; char Cget; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} bool cmp(struct SortNodeType a,struct SortNodeType b)
{
if(a.vi!=b.vi) return a.vi<b.vi;
else
{
return a.ai<b.ai;
}
} int main()
{
in(n),in(k);
for(int i=;i<=n;i++) in(item[i].ai);
for(int i=;i<=n;i++)
{
in(item[i].bi);
item[i].vi=item[i].ai-item[i].bi;
}
sort(item+,item+n+,cmp);
int pos=;
for(int i=;i<=n;i++)
{
if(item[i].vi<=) pos++;
else break;
}
k=max(k,pos);
for(int i=;i<=k;i++) ans+=item[i].ai;
for(int i=k+;i<=n;i++) ans+=item[i].bi;
cout<<ans;
return ;
}

最新文章

  1. Node.js:events事件模块
  2. iOS开发--Swift RAC响应式编程初探
  3. eclipse导入项目出现叹号处理方法:
  4. javascript变量声明 及作用域
  5. JavaScript中的this指向
  6. Salesforce 执行顺序
  7. postfix config
  8. Selenium3笔记-WebDriver源码初探
  9. 四则运算 Day2
  10. spring bean实例化方式
  11. javaweb之Java基础加强
  12. Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP
  13. Appium python自动化测试系列之滑动函数封装实战(八)
  14. Android studio打开项目一直卡住
  15. boost编译随笔
  16. java_24.1文件流的应用--复制文件
  17. maven2中snapshot快照库和release发布库的应用
  18. centos7上安装 mysql
  19. 文字识别:CRNN
  20. DA14580_583_DK_II开发板入门笔记

热门文章

  1. python从列表中删除相邻重复元素
  2. python元组的相对不可变性
  3. Linux基础学习-使用vsftpd服务传输文件
  4. virtualbox安装win7系统报错(“FATAL:No bootable medium found!”)
  5. NoSQL 数据库之MongoDB
  6. python3与python2的编码问题
  7. BZOJ 3351: [ioi2009]Regions
  8. HDU 3315 KM My Brute
  9. HDU 3488 KM Tour
  10. JS实现——俄罗斯方块