【贪心】Codeforces Round #402 (Div. 2) C. Dishonest Sellers
按照b[i]-a[i],对物品从大到小排序,如果这个值大于零,肯定要立刻购买,倘若小于0了,但是没买够K个的话,也得立刻购买。
#include<cstdio>
#include<algorithm>
using namespace std;
struct Point
{
int x,y;
}a[200010];
int n,K,ans;
bool cmp(const Point &a,const Point &b)
{
return a.y-a.x>b.y-b.x;
}
int main()
{
// freopen("c.in","r",stdin);
scanf("%d%d",&n,&K);
for(int i=1;i<=n;++i)
scanf("%d",&a[i].x);
for(int i=1;i<=n;++i)
scanf("%d",&a[i].y);
sort(a+1,a+n+1,cmp);
int i;
for(i=1;i<=n;++i)
{
if(i>K && a[i].y-a[i].x<0)
break;
ans+=a[i].x;
}
for(;i<=n;++i)
ans+=a[i].y;
printf("%d\n",ans);
return 0;
}
【贪心】Codeforces Round #402 (Div. 2) C. Dishonest Sellers的更多相关文章
- 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 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)
		
Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...
 - 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
		
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
 - 贪心 Codeforces Round #301 (Div. 2) B. School Marks
		
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
 - 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
		
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
 - 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
		
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
 - 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
		
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
 - 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
		
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
 
随机推荐
- 从零开始学习MXnet(一)
			
最近工作要开始用到MXnet,然而MXnet的文档写的实在是.....所以在这记录点东西,方便自己,也方便大家. 我觉得搞清楚一个框架怎么使用,第一步就是用它来训练自己的数据,这是个很关键的一步. 一 ...
 - Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum
			
E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...
 - springboot之模板
			
转:http://jisonami.iteye.com/blog/2301387,http://412887952-qq-com.iteye.com/blog/2292402 整体步骤:(1) ...
 - namesilo注册域名用来做域名邮箱
			
重要的话说三遍: (一定不要再国内注册域名,不要买国内的空间) (一定不要再国内注册域名,不要买国内的空间) (一定不要再国内注册域名,不要买国内的空间) 使用的是腾讯企业邮箱,有一个缺点:不支持自定 ...
 - TCP ------ TCP四次挥手(断开连接)及断开过程
			
1.正常情况下,调用close(),产生的其中一个效果就是发送FIN,只有双方都调用close(),才会出现正常的四次挥手. 2.如果是服务器,发起四次挥手是在关闭accept()返回的套接字,而不是 ...
 - [bzoj3994][SDOI2015]约数个数和-数论
			
Brief Description 计算\(\sum_{i\leqslant n}\sum_{j\leqslant m}\sigma_0(ij)\). Algorithm Design 首先证明一个结 ...
 - python 学习笔记 aiohttp
			
asyncio可以实现单进程并发IO操作,如果仅用在客户端,发挥的威力并不大,如果把asyncio用在服务器端,由于http链接就是IO操作, 因此可以用单线程+coroutine实现多客户的高并发支 ...
 - Oracle基础 01 表空间 tablespace
			
--查看表空间 select * from dba_tablespaces; select * from v$tablespace; select * from dba_data_files; --查 ...
 - php性能调试工具介绍
			
php版本:php7 xhprof: xhprof是php5.*下很好的性能测试工具,配合xhprof_html能够图形显示测试结果,基本够用, 但已经没人维护了. tideways: 在php7下, ...
 - Git-ssh登录github
			
生成你的ssh-key $ ssh-keygen -t rsa -b 4096 -C "SaphhireCastle@163.com" 默认目录为:/Users/you/id_r ...