按照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的更多相关文章

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

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

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

  3. Codeforces Round #402 (Div. 2)

    Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...

  4. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  5. 贪心 Codeforces Round #301 (Div. 2) B. School Marks

    题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...

  6. 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

    题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...

  7. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

  8. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  9. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

随机推荐

  1. http get post 参数校验

    spring boot 常见http get ,post请求参数处理   在定义一个Rest接口时通常会利用GET.POST.PUT.DELETE来实现数据的增删改查:这几种方式有的需要传递参数,后台 ...

  2. Fabric证书解析

    一.证书目录解析   通过cryptogen生成所有证书文件后,以peerOrgannizations的第一个组织树org1为例,每个目录和对应文件的功能如下:   ca: 存放组织的根证书和对应的私 ...

  3. Kafka配置文档

    http://kafka.apache.org/08/configuration.html

  4. scala(一种静态语言)

    语法: 关键字 val(表示:值) 不可变 ex: val a:Int=1   或者   val a=1(会自动识别类型,无基本类与包装类之分) 输出:a:Int=1 关键字var ex: var a ...

  5. 最短路径算法 SP

    dijkstra求最短路径长度 dijkstra求最短路并记录路径 #include<stdio.h> #include<string.h> #include<stack ...

  6. JAVA程序打包成exe文件详细图解

    我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: eclipse ...

  7. loj6029 「雅礼集训 2017 Day1」市场

    传送门:https://loj.ac/problem/6029 [题解] 考虑如果有一些近似连续的段 比如 2 2 2 3 3 3,考虑在除3意义下,变成0 0 0 1 1 1,相当于整体-2 又:区 ...

  8. 标签 JLable 类

    标签JLable上可以添加图像,当鼠标停留在标签上时,可以显示一段提示文字. package first; import javax.swing.*; import java.awt.*; impor ...

  9. twitter api的使用获取关注者的时间线

    # -*- coding: utf-8 -*- from tweepy import OAuthHandler import datetime import pandas as pd import t ...

  10. 【反演复习计划】【bzoj1011】zap-queries

    快三个月没做反演题了吧…… 感觉高一上学期学的全忘了…… 所以还得从零开始学推式子. # bzoj1011 标签(空格分隔): 未分类 --- 原题意思是求以下式子:$Ans=\sum\limits_ ...