贪心。

如果这周便宜,那么肯定这周买。另外要求这周至少买到$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. Fragment+ViewPager实现仿微信点击和滑动切换界面

    这是在我写的新闻App中实现的界面切换 贴出切换界面的主要代码: xml代码: <span style="font-size:14px;"> <android.s ...

  2. 深入HBase架构解析(一)

    前记 公司内部使用的是MapR版本的Hadoop生态系统,因而从MapR的官网看到了这篇文文章:An In-Depth Look at the HBase Architecture,原本想翻译全文,然 ...

  3. bzoj3043 IncDec Sequence

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3043 [题解] 比较神奇的一道题,开始没往差分的角度上想,所以没想出来. 考虑查分数组,有$ ...

  4. UIActivityIndicatorView---iOS-Apple苹果官方文档翻译

    本系列所有开发文档翻译链接地址: iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 UIActivityIndicatorViewactivityIndicatorVi ...

  5. python初步学习-python控制流

    语句书写规范 缩进在python语言书写中非常重要,如果缩进不规范,执行程序将会报错 引用维基百科中的叙述: Python開發者有意讓違反了縮排規則的程序不能通過編譯,以此來強迫程序員養成良好的編程習 ...

  6. HTTP和HTTPS详解。

    一,HTTP和HTTPS基本概念 深入学习某个东西时,我们先来从维基百科上看看它俩的概念. HTTP:超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是一 ...

  7. vim 实现括号以及引号的自动补全

    编辑文件/etc/vim/vimrc sudo vim /etc/vim/vimrc 在最后添加 inoremap ( ()<ESC>i inoremap [ []<ESC>i ...

  8. js 验证ip列表

    如题. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...

  9. 【Python学习笔记】Coursera课程《Using Python to Access Web Data》 密歇根大学 Charles Severance——Week6 JSON and the REST Architecture课堂笔记

    Coursera课程<Using Python to Access Web Data> 密歇根大学 Week6 JSON and the REST Architecture 13.5 Ja ...

  10. linux系统下git使用

    转载:http://www.cnblogs.com/bear2flymoon/p/4335364.html?ADUIN=563508762&ADSESSION=1430887070&A ...