贪心。

如果这周便宜,那么肯定这周买。另外要求这周至少买到$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的更多相关文章

  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. NOIP2006 数列

    codevs 1141 数列 http://codevs.cn/problem/1141/ 2006年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB     题目描述  ...

  2. django自带分页代码

    django分页 {% if is_paginated %} <div class="pagination-simple"> <!-- 如果当前页还有上一页,显示 ...

  3. Jmeter 重要测试指标释义

    Aggregate Report 是 JMeter 常用的一个 Listener,中文被翻译为“聚合报告”.今天再次有同行问到这个报告中的各项数据表示什么意思,顺便在这里公布一下,以备大家查阅. 如果 ...

  4. 2016-2017 2 20155335《java程序设计》第四周总结

    #  20155335    <Java程序设计>第四周学习总结 ##  教材学习内容总结 继承,在本职上是特殊到一般的关系,即is—a关系,子类继承父类,表明子类是一种特殊的父类,并且具 ...

  5. 基于 Docker 的 Zabbix 微服务系统

    zabbix 官网提供一个镜像 [ zabbix-appliance ], 可以直接拉起一个 zabbix-server. 但是数据库无法分离出来. 本实践使用 zabbix 官方提供的 Docker ...

  6. window对象的方法和属性汇总

    window对象有以下方法: open close alert confirm prompt setTimeout clearTimeout setInterval clearInterval mov ...

  7. js_在原有的日期上添加天数输出添加后的日期

    开始编码工作也有段时间了,想想没有留下点什么,有点遗憾.学到的一些经验,写写,分享一下.也给自己整理一下. 今天分享一下,在原有的日期上添加天数输出添加后的日期.开始做的时候,简单的思路是,直接用ne ...

  8. linux 服务简介

    Linux服务(Linux services)对于每个应用Linux的用户来说都很重要.关闭不需要的服务,可以让Linux运行的更高效,但并不是所有的Linux服务都可以关闭.今天安装了一次CentO ...

  9. 【Python学习笔记】异常处理try-except

    Python异常处理 我们一般使用try-except语句来进行异常处理. 使用except Exception as err可以统一捕捉所有异常,而也可以分开处理单个异常. # 分开捕捉单个异常 t ...

  10. 安全测试===sqlmap(肆)转载

    十八.杂项 1.使用简写 参数:-z 有些参数组合是被经常用到的,如“--batch --random-agent --ignore-proxy --technique=BEU”,这样写一大串很不好看 ...