Description

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个物品,下周买n-k个物品,问总的花费最小

解法:以为是dp,后来用贪心过了,我们先比较两个价格的变化,优先买价格变化小的(只能买当前价格),接下来买价格中最便宜的。

我们记录价格变化,从小到大排序,然后前k个数字相加,然后买价格最便宜的

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream> // C++头文件,C++完全兼容C
#include <algorithm> // C++头文件,C++完全兼容C
#define fre freopen("in.txt","r",stdin) //以文件代替控制台输入,比赛时很常用,能缩短输入测试样例的时间
#define INF 0x3f3f3f3f
#define inf 1e60
using namespace std; // C++头文件,C++完全兼容C
#define N 200005 // 宏定义
#define LL long long //宏定义 int a[N],b[N];
struct P
{
int x,y,ans;
}H[N];
int ans;
bool cmd(P a,P b)
{
return a.ans<b.ans;
} int main()
{
int n,k;
cin>>n>>k;
for(int i=;i<=n;i++)
{
cin>>H[i].x;
}
for(int i=;i<=n;i++)
{
cin>>H[i].y;
H[i].ans=H[i].x-H[i].y;
}
sort(H+,H++n,cmd);
for(int i=;i<=k;i++)
{
ans+=H[i].x;
} for(int i=k+;i<=n;i++)
{
ans+=min(H[i].x,H[i].y);
}
cout<<ans<<endl;
return ;
}

最新文章

  1. 【亚瑟士 ASICS 系列】
  2. 洛谷P1134 阶乘问题
  3. 安装ECshop普遍问题的解决方法
  4. DBContext
  5. Linux定时任务crontab每三秒执行一次shell
  6. 学习笔记--【转】Parameter与Attribute的区别&amp;servletContext与ServletConfig区别
  7. Fatal error: Class &#39;ZipArchive&#39; not found的解决办法
  8. 1247 排排站 USACO(查分+hash)
  9. Spark学习笔记-三种属性配置详细说明【转】
  10. Mysql找回root密码
  11. channelartlist|频道文档:
  12. egametang框架服务端运行流程
  13. 电子称DIY(贴应变片+写代码)
  14. 搭建centos7的开发环境1-系统安装及Python配置
  15. ios sdk 配置路径
  16. AllPay(欧付宝)支付接口集成
  17. Linux 使用 github 常用命令
  18. yum小结
  19. LTE-A 载波聚合(Carrier Aggregation)介绍【转】
  20. FabricExpress.net supply high quality quilting fabric

热门文章

  1. openwrt: patch-dtb
  2. 利用NSMutableAttributedString实现label上字体大小颜色行间距的改变
  3. eclipse配置android
  4. LeetCode(67)题解: Add Binary
  5. 0 lrwxrwxrwx. 1 root root 13 Nov 20 12:44 scala -&gt; scala-2.12.4
  6. C# 软件实现远程桌面调用
  7. Fastreport生成WEB报表
  8. poj2761静态区间第k大
  9. YTU 2203: 最小节点(线性表)
  10. dede摘要长度,dedecms摘要限制,dedecms摘要字数