1.题目描述:

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.

2.题意概述:

一个人打算这两周去商店总共买n件衣服,今日至少要买k件,剩下的可以下周买,正逢打折活动,持续一周,但是老板很黑,有些衣服本周打折的价格反而比下周不打折的价格还高,要你帮他算一下,他买这n件衣服的最少花费。

3.解题思路:

今日至少要买k件,那么肯定先买“真”打折的衣服,如果“真”打折衣服买完还不够k件,则贪心地买差价最小的“假”打折衣服。

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 200100
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e 2.718281828459
#define mod (int)1e9 + 7
using namespace std;
typedef long long ll;
struct node
{int a, b, vis;
}p[maxn];
bool cmpa(node x, node y)
{if (x.a == y.a)return x.b < y.b;return x.a < y.a;
}
bool cmp(node x, node y)
{return x.a - x.b < y.a - y.b;
}
int main()
{
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);long _begin_time = clock();
#endifint n, k;while (~scanf("%d%d", &n, &k)){for (int i = 0; i < n; i++)scanf("%d", &p[i].a);for (int i = 0; i < n; i++){scanf("%d", &p[i].b);p[i].vis = 0;}sort(p, p + n, cmpa);int cnt = 0, ans = 0;for (int i = 0; i < n; i++)  //先买诚实的产品{if (p[i].a < p[i].b){ans += p[i].a;cnt++;p[i].vis = 1;}}sort(p, p + n, cmp);if (cnt < k)  //只能买说谎的产品了{for (int i = 0; i < n; i++){if (!p[i].vis){if (cnt < k){ans += p[i].a;p[i].vis = 1;cnt++;}elsebreak;}}}// 买剩下的产品for (int i = 0; i < n; i++)if (!p[i].vis)ans += p[i].b;printf("%d\n", ans);}#ifndef ONLINE_JUDGElong _end_time = clock();printf("time = %ld ms.", _end_time - _begin_time);
#endifreturn 0;
}

CF - 779C. Dishonest Sellers 排序+贪心相关推荐

  1. CF 779 C Dishonest Sellers 贪心,排序

    题目链接:见这里 题意:给了一些物品,每个物品有俩个价格,一个是打折前的,一个是打折后的(打折发生在一周后),现在一个人必须先买k个物品,然后剩下的物品既可以选择现在买,也可以选择一周后买,其中打折后 ...

  2. Dishonest Sellers

    题目链接  http://codeforces.com/problemset/problem/779/C C. Dishonest Sellers time limit per test 2 seco ...

  3. LeetCode 2611. 老鼠和奶酪:排序 + 贪心

    [LetMeFly]2611.老鼠和奶酪:排序 + 贪心 力扣题目链接:https://leetcode.cn/problems/mice-and-cheese/ 有两只老鼠和 n 块不同类型的奶酪, ...

  4. POJ3687拓扑排序+贪心

    题意:       给你n个求,他们的重量是1-n(并不是说1号求的重量是1...),然后给你m组关系a,b,表示a的重量小于b的重量,然后让你输出满足要求的前提下每个球的重量,要求字典序最小. 思路 ...

  5. [蓝桥杯][算法提高VIP]线段和点(排序+贪心)

    题目描述 有n个点和m个区间,点和区间的端点全部是整数,对于点a和区间[b,c],若a> =b且a< =c,称点a满足区间[b,c]. 求最小的点的子集,使得所有区间都被满足. 数据规模和 ...

  6. USACO2.1【bfs,排序,贪心,dfs,位运算】

    前言 开始刷USACO的题了. 正题 刷前必备技能:OI常识,bfs,dfs,位运算,基础贪心,快速排序. T1:城堡 TheCastleThe CastleTheCastle 评测记录: https ...

  7. ACM学习历程—HihoCoder1309任务分配(排序 贪心)

    http://hihocoder.com/problemset/problem/1309 题目大意是给定n个任务的起始时间,求问最少需要多少台机器. 有一个贪心的策略就是,如果说对于一个任务结束,必然 ...

  8. BZOJ2535: [Noi2010]Plane 航空管制2(拓扑排序 贪心)

    题意 题目链接 Sol 非常妙的一道题. 首先不难想到拓扑排序,但是直接对原图按\(k\)从小到大拓扑排序是错的.因为当前的\(k\)大并不意味着后面的点\(k\)也大 但是在反图上按\(k\)从大到 ...

  9. leetcode-1833. 雪糕的最大数量(排序+贪心)

    题目链接:https://leetcode.cn/problems/maximum-ice-cream-bars/ 思路 直观想法 在给定的硬币情况下,花最小的钱,买最多的雪糕,一眼贪心. 吐槽一句: ...

最新文章

  1. WEB 测试点总结
  2. 图像调整亮度饱和度 c语言,【C#/WPF】调节图像的HSL(色相、饱和度、明亮度)...
  3. LDO的最小输入输出压差和最小负载电流
  4. QT的第一个程序HELLO WORLD
  5. 云数据中心的网络架构
  6. zookeeper系列(九)zookeeper的会话详解
  7. Android 动画(三)--属性动画
  8. RGB、YUV像素基础知识及处理数据
  9. phpstorm破解安装
  10. [机器学习笔记] Note4--逻辑回归
  11. centos7下载安装mysql步骤_Linux-centos7安装mysql步骤
  12. springboot整合使用rocketMq
  13. 手机号归属地区编码_Excel隐藏手机号中间4位的6种方法,你见过几种?
  14. 当你想对常用网站定制属于自己的颜色,然而又没人理你怎么办
  15. 网吧 电影系统 php,网吧电影服务器解决方案完全指南(一)
  16. 运行QT打包后的程序出现d:\Program Files (x86)\SogouInput\...错误
  17. 桌面cpu与服务器cpu天梯,桌面CPU性能排行 桌面CPU天梯图2017年6月最新版
  18. 和刘备相关的人(八 )
  19. 【华为机试真题 C++】一种字符串压缩表示的解压-100
  20. 转-基于OpenGL的3D天空仿真

热门文章

  1. 开发中的“通盘可以无妙手”
  2. AcrelCloud-6000安全用电云平台在某景区的应用
  3. Nuxt(安装部署)爬坑指南
  4. SQL语句中单引号、双引号和反引号的区分
  5. 计算机科学与技术英译,计算机科学与技术外文翻译、中英对照、英汉互译.doc...
  6. 简单的统计学:如何用Python计算扑克概率
  7. BLE连接过程分析及异常断开0x3e错误原因分析
  8. linux下磁盘管理之利器 lvm使用介绍
  9. js css鼠标经过下划线,Css、JS实现下划线动效
  10. Ubuntu 20.04.3 启动sshd失败,报错:Failed to start OpenBSD Secure Shell server