贪心。

如果这周便宜,那么肯定这周买。另外要求这周至少买到$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. [C#] 类型学习笔记二:详解对象之间的比较

    继上一篇对象类型后,这里我们一起探讨相等的判定. 相等判断有关的4个方法 CLR中,和相等有关系的方法有这么4种: (1) 最常见的 == 运算符 (2) Object的静态方法ReferenceEq ...

  2. mysql 字段为NULL的一些操作

    1. 修改字段为NULL update tableName set column1 = null where id = 1 2. 字段是否为NULL (1)字段为空 select * tableNam ...

  3. vs 自定义插件(扩展工具)

    此篇仅仅是因为好奇,实现的是完全没有价值的东西,当然,通过此篇的尝试,后续可以在适当的场景,深入的研究Visual Studio自定义插件的应用. 实现功能如下: 在鼠标选中的地方,显示一下创建人,创 ...

  4. iOS排序

    NSArray *originalArray = @[@,@,@,@,@]; //block比较方法,数组中可以是NSInteger,NSString(需要转换) NSComparator finde ...

  5. java collection(一)

    1.Collection层次结构: 2.集合Conllection的基本概念: (1)集合的基本认识:如StringBuffer&StringBuilder是集合(存储的对象类型是String ...

  6. Docker explainations

    What does docker run --link mean, what's the usage? link 是在两个contain之间建立一种父子关系,父container中的web,可以得到子 ...

  7. fs.createReadStream(filepath).pipe(response);这句是什么意思?

    'use strict'; var fs = require('fs'), url = require('url'), path = require('path'), http = require(' ...

  8. url编码模块

    use LWP::SImple; use URI::Escape; encoded_string = uri_escape(raw_string); get(encoded_string);

  9. Msfvenom学习总结-MSF反弹webshell

    1.    –p (- -payload-options) 添加载荷payload. 载荷这个东西比较多,这个软件就是根据对应的载荷payload生成对应平台下的后门,所以只有选对payload,再填 ...

  10. Override 和 Overload 的含义和区别

    Override 1.方法重写.覆盖: 2.重写是父类与子类之间多态性的一种表现: 3.方法名,参数,返回值相同: 4.存在于子类和父类之间: 5.修饰为final的方法,不能被重写: Overloa ...