题目链接  http://codeforces.com/problemset/problem/779/C

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

题目大意:

一个商店想要打折卖东西(但是店员并不是很诚实,有些商品打完折后更贵)。商店共有n件商品,一个人想要全部买了。这个人分两次买,第一次是在打折期买至少k件商品;第二次是在打折后买剩下的商品。问:这个人最少花费多少钱能够把n件商品买了。

按照第一组测试数据说吧,这样会更清晰。3 1 分别表示所有商品件数  该人第一次至少买的数目。第二行表示打折期n件商品的价格。第三行表示原价n件商品的价格。

解题思路:定义一个c[]数组表示c[i]=a[i]-b[i],然后对c[]数组进行从小到大排序。用sum记录按照原价所有商品的价格总和。然后让数组c的钱k项依次与sum相加。完后如果接下来的c[i]<0的话,那么继续相加(因为第一次至少买k件商品,如果多于k件并且打折后便宜,那么久继续买)

代码:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int n,k,ans,z;int a[200005],b[200005],c[200005];while(cin>>n>>k){ans=0;for(int i=0;i<=n-1;i++)cin>>a[i];for(int i=0;i<=n-1;i++){cin>>b[i];ans=ans+b[i];}for(int i=0;i<=n-1;i++)c[i]=a[i]-b[i];sort(c,c+n);for(int i=0;;i++){if(k==0)          //如果k件商品买够了{if(c[i]<0)    //如果还打折期便宜的话就继续买{ans=ans+c[i];continue;}else         //否则表示打折后比打折前更贵,呢么就不买了,等打折期过了再买break;}if(k>0)          //若果k件商品还没有买够,那么久继续买{ans=ans+c[i];k--;}}cout<<ans<<endl;}return 0;
}

Dishonest Sellers相关推荐

  1. CF - 779C. Dishonest Sellers 排序+贪心

    1.题目描述: C. Dishonest Sellers time limit per test 2 seconds memory limit per test 256 megabytes input ...

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

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

  3. 我们建议您在Google的sellers.json文件中公开您的卖方信息

    做Adsense好多年了,今天登陆后台发现有条通知:我们建议您在 Google 的 sellers.json 文件中公开您的卖方信息:访问"帐号设置"页可查看您当前的公开状态. 先 ...

  4. 论文学习笔记 Diogenes: Lightweight Scalable RSA Modulus Generation with a Dishonest Majority

    论文学习笔记 Diogenes: Lightweight Scalable RSA Modulus Generation with a Dishonest Majority Introduction ...

  5. 中国科技大学计算机学院叶辉,中国科技大学计算机科学与技术学院导师教师师资介绍简介-黄文超...

    中国科技大学计算机科学与技术学院导师教师师资介绍简介-黄文超本站小编 Free考研考试/2021-04-24 E - Mail:huangwc@ustc.edu.cn 个人主页:http://staf ...

  6. 比特币:一种点对点的电子现金系统

    比特币:一种点对点的电子现金系统 Bitcoin: A Peer-to-Peer Electronic Cash System 原文作者:中本聪(Satoshi Nakamoto) 执行翻译:8btc ...

  7. java 统计文本中出现概率最高的10个字符串!!

    以前经常在CSDN博客上看别人的文章,有时是遇到难题为了寻找思路,有时则是为了偷懒,直接复制别人的源代码,所以对于写这些博客的技术大神,我都是佩服且感激的.感激于他们把我的问题分析的如此透彻明白,佩服 ...

  8. 豪华摆脱游戏中大奖_中大奖! 如何找到赚钱的领域

    豪华摆脱游戏中大奖 Investing in registered or expired domains can increase the visibility of your Website and ...

  9. 比特币创世文 Bitcoin: A Peer-to-Peer Electronic Cash System 解读

    比特币创世文 Bitcoin: A Peer-to-Peer Electronic Cash System 解读 一夜之间,区块链再次火起来.网络上大量的讲解分析区块链比特币的文章蜂拥而出.我是一个考 ...

最新文章

  1. C++11中std::function的使用
  2. mysql 2003错误 10055_MYSQL无法连接 提示10055错误的解决方法
  3. 《让系统发生重大宕机事故的15个方法》
  4. php获得前一天,php 获取前一天、后一天等日期的方法
  5. numpy的常规使用(数组合并、拼接、添加)
  6. Lync Server 2010 语音质量
  7. cura-engine学习(1)
  8. worknc的后处理如何安装_如何选择永磁变频螺杆空压机的冷干机?
  9. mysql按照日期先去重在分组_【巨杉数据库Sequoiadb】【咨询】【数据操作】【聚集查询】在执行聚集查询时,字符类型的字段能否按照实际内容进行分组去重...
  10. 3.5.基于STC89C52+MC20的短信远程控制开关LCD1602显示
  11. boost 学习笔记
  12. shell通过sshpass远程ssh执行命令
  13. 【100题】第十二题(特殊的递加)
  14. Valgrind User Manual
  15. C#——教务管理系统设计01(20181003)
  16. CRM 客户管理系统(SpringBoot+MyBatis)
  17. 台湾大学林轩田机器学习技法课程学习笔记8 -- Adaptive Boosting
  18. MySQL- 使用PreparedStatement接口,实现数据表的更新,查询操作
  19. 使用cert-manager给阿里云的DNS域名授权SSL证书
  20. pageCache和bufferCache

热门文章

  1. 【华为OD统一考试B卷 | 200分】 连续出牌数量(C++ Java JavaScript )
  2. 什么时候用p标签,什么时候用li标签
  3. 5.嫌疑犯 (5分)
  4. c语言memcpy是什么,C语言memcpy函数的用法
  5. Django项目使用gunicorn
  6. 社区源码:如何搭建一个企业社区
  7. React单元测试:Jest+Enzyme
  8. 无线传感器网络—拓扑管理
  9. AuthenticationManager认证
  10. ALTER DATABASE 与 ALTER TABLESPACE OFFLINE的区别