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 ;
}

Codeforces Round #402 (Div. 2) C的更多相关文章

  1. Codeforces Round #402 (Div. 2)

    Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...

  2. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  3. Codeforces Round #402 (Div. 2) A,B,C,D,E

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #402 (Div. 2) D. String Game

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  5. Codeforces Round #402 (Div. 2) A B C sort D二分 (水)

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. 【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding

    暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=1 ...

  7. Codeforces Round #402 (Div. 2) 题解

    Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...

  8. Codeforces Round #402 (Div. 2) 阵亡记

    好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...

  9. CodeForces Round #402 (Div.2) A-E

    2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...

  10. Codeforces Round #402 (Div. 2) B

    Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. ...

随机推荐

  1. ViewGroup如何分发事件

    dispatchTouchEvent事件派发显示隧道方式.再是冒泡方式隧道方式传递,直道某一个元素消耗此事件,由上至下逐层分发视图.冒泡方式传递,当某个视图消耗事件后其return boolean 是 ...

  2. 你的以太网速度足够快吗?四种更快的速度正在路上&#183;&#183;&#183;&#183;&#183;&#183;

    以太网的未来将远远超越下一个最快速度:为无处不在的网络协议绘制路径的网络project师们正在寻找新版本号来服务于各种应用程序. 在上周六的以太网联盟(一个行业组织,用于促进IEEE以太网标准)会议上 ...

  3. SpringMVC实战(注解)

    1.前言 前面几篇介绍了SpringMVC中的控制器以及视图之间的映射方式,这篇来解说一下SpringMVC中的注解,通过注解能够非常方便的訪问到控制器中的某个方法. 2.配置文件配置 2.1 注解驱 ...

  4. 增加实时性的异常url检测

    技能点: 搭建服务器.restfulapi 在py脚本中调取另一个脚本执行

  5. SpringMVC 之 Controller、Service层职责

    Controller层 1.接收httpRequest/requestDTO数据 ,检查接收数据参数与格式. 2.传递参数至Service层并接收返回responseDTO数据. 3.包装respon ...

  6. Flume 和 kafka的区别和对比

    定义: Flume:是Cloudera提供的一个分布式的海量日志采集.聚合和传输的系统: Kafka:是一种高吞吐量的分布式发布订阅消息系统: 各特点: 场景: Flume主要是和HDFS\HBase ...

  7. MongoDB3.6.3 windows安装配置、启动

    1.官网下载MongoDB的安装包 2.安装中一直Next即可安装成功,不过需要注意的是: 可以自定义安装,选择安装路径 值得注意的还有,安装中因为下载compass十分缓慢.把下面默认选中的勾去掉 ...

  8. FileInputStream和FileReader

    这两个类都可以读入数据到缓冲区,FileInputStream在传递到buffer的时候要用byte定义buffer,不然报错.比如: byte [] buffer = new byte[100]; ...

  9. HNOI2008 越狱 (组合数学)

    传送门 应该是HNOI2008年最简单的一道题了吧……简单的组合数题,不过要换个思路. 我们直接考虑发生越狱的情况似乎有点复杂,那我们换个思路,考虑不发生越狱的情况,也就是两个有相同宗教的人不会坐在一 ...

  10. 洛谷P2575高手过招——SG函数初试

    题目:https://www.luogu.org/problemnew/show/P2575 第一次用SG函数解决问题,有许多不熟练的地方: 试图按自己的理解写一个dfs,结果错了(连题都没读对,以为 ...