首页 > 其他 > 详细

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

时间:2017-02-26 20:50:04      阅读:230      评论:0      收藏:0      [点我收藏+]

按照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

原文:http://www.cnblogs.com/autsky-jadek/p/6445554.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!