贪心。

如果这周便宜,那么肯定这周买。另外要求这周至少买到$k$个,那么肯定是需要额外购买差价小的。

  1. #include<map>
  2. #include<set>
  3. #include<ctime>
  4. #include<cmath>
  5. #include<queue>
  6. #include<string>
  7. #include<vector>
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<iostream>
  11. #include<algorithm>
  12. #include<functional>
  13. using namespace std;
  14.  
  15. int n,k;
  16. int a[], b[],f[],sum;
  17. struct X
  18. {
  19. int a,b;
  20. }s[];
  21.  
  22. bool cmp(X a,X b)
  23. {
  24. return a.a-a.b<b.a-b.b;
  25. }
  26.  
  27. int main()
  28. {
  29. scanf("%d%d",&n,&k);
  30. for(int i=;i<=n;i++) scanf("%d",&a[i]);
  31. for(int i=;i<=n;i++) scanf("%d",&b[i]);
  32.  
  33. int ans=;
  34. for(int i=;i<=n;i++)
  35. {
  36. if(a[i]<=b[i]) ans=ans+a[i],f[i]=, sum++;
  37. }
  38.  
  39. if(sum>=k)
  40. {
  41. for(int i=;i<=n;i++)
  42. {
  43. if(f[i]) continue;
  44. ans=ans+b[i];
  45. }
  46. }
  47.  
  48. else
  49. {
  50. int sz=;
  51. for(int i=;i<=n;i++)
  52. {
  53. if(f[i]) continue;
  54. s[sz].a =a[i];
  55. s[sz].b = b[i];
  56. sz++;
  57. }
  58. sort(s,s+sz,cmp);
  59.  
  60. int y = ;
  61. for(int i=;i<sz;i++)
  62. {
  63. if(y<k-sum) ans=ans+s[i].a;
  64. else ans=ans+s[i].b;
  65. y++;
  66. }
  67.  
  68. }
  69.  
  70. printf("%d\n",ans);
  71.  
  72. return ;
  73. }

CodeForces 779C Dishonest Sellers的更多相关文章

  1. AC日记——Dishonest Sellers Codeforces 779c

    C. Dishonest Sellers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. 【codeforces 779C】Dishonest Sellers

    [题目链接]:http://codeforces.com/contest/779/problem/C [题意] 有n个商品; 打折前买和打折后买的价格不一样; 且必须有至少k个商品在打折前买; 问你买 ...

  3. 【贪心】Codeforces Round #402 (Div. 2) C. Dishonest Sellers

    按照b[i]-a[i],对物品从大到小排序,如果这个值大于零,肯定要立刻购买,倘若小于0了,但是没买够K个的话,也得立刻购买. #include<cstdio> #include<a ...

  4. CF779C(round 402 div.2 C) Dishonest Sellers

    题意: Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last ...

  5. Codeforces #402

    目录 Codeforces #402 Codeforces #402 Codeforces 779A Pupils Redistribution 链接:http://codeforces.com/co ...

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

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

  7. 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 ...

  8. 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 ...

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

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

随机推荐

  1. Javascript利用递归实现数组的快速排序

    // 定义快速排序方法 function quickSort(arr){ // 设置递归的终止条件 if( arr.length <= 1){ return arr; } // 获得数组arr的 ...

  2. HDU 5942 Just a Math Problem 容斥 莫比乌斯反演

    题意:\( g(k) = 2^{f(k)} \) ,求\( \sum_{i = 1}^{n} g(i) \),其中\( f(k)\)代表k的素因子个数. 思路:题目意思很简单,但是着重于推导和简化,这 ...

  3. 2015/9/10 Python基础(11):错误和异常

    程序在执行的过程中会产生异常,出现错误在以前的一个时期是致命的,后来随着程序的发展,使得一些错误的处理方式是柔和的,发生错误会产生一些错误的诊断信息和一些模糊的提示.帮助我们来处理异常.今天将学习Py ...

  4. 2015/8/30 Python基础(4):序列操作符

    序列是指成员有序排列,可以通过下标偏移量访问的类型.Python序列包括:字符串.列表和元组.序列的每个元素可以指定一个偏移量得到,多个元素是通过切片操作得到的.下标偏移量从0开始计数到总数-1结束. ...

  5. [洛谷P2051] [AHOI2009]中国象棋

    洛谷题目链接:[AHOI2009]中国象棋 题目描述 这次小可可想解决的难题和中国象棋有关,在一个N行M列的棋盘上,让你放若干个炮(可以是0个),使得没有一个炮可以攻击到另一个炮,请问有多少种放置方法 ...

  6. PowerDesigner16 修改表或表的字段Name的时候不让Code不自动跟着变

    在修改表或表的字段Name的时候不让Code不自动跟着变,设置如下: tools-> General   Options-> Dialog 去掉勾选 Name To Code mirror ...

  7. 元类编程--__getattr__, __getattribute__

    #__getattr__, __getattribute__ #__getattr__ 就是在查找不到属性的时候调用 from datetime import date class User: def ...

  8. Vuejs - 组件式开发

    初识组件 组件(Component)绝对是 Vue 最强大的功能之一.它可以扩展HTML元素,封装可复用代码.从较高层面讲,可以理解组件为自定义的HTML元素,Vue 的编译器为它添加了特殊强大的功能 ...

  9. js_参数的get传输,从一个页面到另外一个页面。

    2017年10月31日,今天是万圣节,欢乐谷搞事情. 刚接触前端那会是分不清,前端和后台的,后台的数据如何传输到前端的. 现在用的还是Jquery的ajax请求后台数据到前端页面的,需要学习的地方还有 ...

  10. hdu 3790 最短路径问题(双重权值,dijkstra算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3790 题目大意:题意明了,输出最短路径及其花费. 需要注意的几点:(1)当最短路径相同时,输出最小花费 ...