CodeForces 779C Dishonest Sellers
贪心。
如果这周便宜,那么肯定这周买。另外要求这周至少买到$k$个,那么肯定是需要额外购买差价小的。
- #include<map>
- #include<set>
- #include<ctime>
- #include<cmath>
- #include<queue>
- #include<string>
- #include<vector>
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #include<functional>
- using namespace std;
- int n,k;
- int a[], b[],f[],sum;
- struct X
- {
- int a,b;
- }s[];
- bool cmp(X a,X b)
- {
- return a.a-a.b<b.a-b.b;
- }
- int main()
- {
- scanf("%d%d",&n,&k);
- for(int i=;i<=n;i++) scanf("%d",&a[i]);
- for(int i=;i<=n;i++) scanf("%d",&b[i]);
- int ans=;
- for(int i=;i<=n;i++)
- {
- if(a[i]<=b[i]) ans=ans+a[i],f[i]=, sum++;
- }
- if(sum>=k)
- {
- for(int i=;i<=n;i++)
- {
- if(f[i]) continue;
- ans=ans+b[i];
- }
- }
- else
- {
- int sz=;
- for(int i=;i<=n;i++)
- {
- if(f[i]) continue;
- s[sz].a =a[i];
- s[sz].b = b[i];
- sz++;
- }
- sort(s,s+sz,cmp);
- int y = ;
- for(int i=;i<sz;i++)
- {
- if(y<k-sum) ans=ans+s[i].a;
- else ans=ans+s[i].b;
- y++;
- }
- }
- printf("%d\n",ans);
- return ;
- }
CodeForces 779C Dishonest Sellers的更多相关文章
- AC日记——Dishonest Sellers Codeforces 779c
C. Dishonest Sellers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 【codeforces 779C】Dishonest Sellers
[题目链接]:http://codeforces.com/contest/779/problem/C [题意] 有n个商品; 打折前买和打折后买的价格不一样; 且必须有至少k个商品在打折前买; 问你买 ...
- 【贪心】Codeforces Round #402 (Div. 2) C. Dishonest Sellers
按照b[i]-a[i],对物品从大到小排序,如果这个值大于零,肯定要立刻购买,倘若小于0了,但是没买够K个的话,也得立刻购买. #include<cstdio> #include<a ...
- 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 ...
- Codeforces #402
目录 Codeforces #402 Codeforces #402 Codeforces 779A Pupils Redistribution 链接:http://codeforces.com/co ...
- Codeforces Round #402 (Div. 2) A+B+C+D
Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...
- 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 ...
- 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 ...
- CodeForces Round #402 (Div.2) A-E
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...
随机推荐
- Javascript利用递归实现数组的快速排序
// 定义快速排序方法 function quickSort(arr){ // 设置递归的终止条件 if( arr.length <= 1){ return arr; } // 获得数组arr的 ...
- HDU 5942 Just a Math Problem 容斥 莫比乌斯反演
题意:\( g(k) = 2^{f(k)} \) ,求\( \sum_{i = 1}^{n} g(i) \),其中\( f(k)\)代表k的素因子个数. 思路:题目意思很简单,但是着重于推导和简化,这 ...
- 2015/9/10 Python基础(11):错误和异常
程序在执行的过程中会产生异常,出现错误在以前的一个时期是致命的,后来随着程序的发展,使得一些错误的处理方式是柔和的,发生错误会产生一些错误的诊断信息和一些模糊的提示.帮助我们来处理异常.今天将学习Py ...
- 2015/8/30 Python基础(4):序列操作符
序列是指成员有序排列,可以通过下标偏移量访问的类型.Python序列包括:字符串.列表和元组.序列的每个元素可以指定一个偏移量得到,多个元素是通过切片操作得到的.下标偏移量从0开始计数到总数-1结束. ...
- [洛谷P2051] [AHOI2009]中国象棋
洛谷题目链接:[AHOI2009]中国象棋 题目描述 这次小可可想解决的难题和中国象棋有关,在一个N行M列的棋盘上,让你放若干个炮(可以是0个),使得没有一个炮可以攻击到另一个炮,请问有多少种放置方法 ...
- PowerDesigner16 修改表或表的字段Name的时候不让Code不自动跟着变
在修改表或表的字段Name的时候不让Code不自动跟着变,设置如下: tools-> General Options-> Dialog 去掉勾选 Name To Code mirror ...
- 元类编程--__getattr__, __getattribute__
#__getattr__, __getattribute__ #__getattr__ 就是在查找不到属性的时候调用 from datetime import date class User: def ...
- Vuejs - 组件式开发
初识组件 组件(Component)绝对是 Vue 最强大的功能之一.它可以扩展HTML元素,封装可复用代码.从较高层面讲,可以理解组件为自定义的HTML元素,Vue 的编译器为它添加了特殊强大的功能 ...
- js_参数的get传输,从一个页面到另外一个页面。
2017年10月31日,今天是万圣节,欢乐谷搞事情. 刚接触前端那会是分不清,前端和后台的,后台的数据如何传输到前端的. 现在用的还是Jquery的ajax请求后台数据到前端页面的,需要学习的地方还有 ...
- hdu 3790 最短路径问题(双重权值,dijkstra算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3790 题目大意:题意明了,输出最短路径及其花费. 需要注意的几点:(1)当最短路径相同时,输出最小花费 ...