CodeForces 779C Dishonest Sellers
贪心。
如果这周便宜,那么肯定这周买。另外要求这周至少买到$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的更多相关文章
- AC日记——Dishonest Sellers Codeforces 779c
C. Dishonest Sellers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 【codeforces 779C】Dishonest Sellers
[题目链接]:http://codeforces.com/contest/779/problem/C [题意] 有n个商品; 打折前买和打折后买的价格不一样; 且必须有至少k个商品在打折前买; 问你买 ...
- 【贪心】Codeforces Round #402 (Div. 2) C. Dishonest Sellers
按照b[i]-a[i],对物品从大到小排序,如果这个值大于零,肯定要立刻购买,倘若小于0了,但是没买够K个的话,也得立刻购买. #include<cstdio> #include<a ...
- 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 ...
- Codeforces #402
目录 Codeforces #402 Codeforces #402 Codeforces 779A Pupils Redistribution 链接:http://codeforces.com/co ...
- Codeforces Round #402 (Div. 2) A+B+C+D
Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...
- 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 ...
- 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 ...
- CodeForces Round #402 (Div.2) A-E
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...
随机推荐
- 利用pdfJS实现以读取文件流方式在线展示pdf文件
第一步:下载源码https://github.com/mozilla/pdf.js 第二步:构建PDF.js 第三步:修改viewer.js var DEFAULT_URL = 'compressed ...
- 【c#】winform 上传图片
1.拖拽上传图片 1.1.后台代码中修改窗体属性,添加 AllowDrop = true 1.2.给窗体添加拖拽事件,在事件列表找到拖拽 双击即可: 在 DragDrop 生成的方法中添加代码如下: ...
- centos设置tomcat开机启动
1.编辑开机启动脚本 vi /etc/init.d/tomcat8 #!/bin/bash # tomcat8:start|stop|restart # chkconfig: 345 90 10 # ...
- PowerDesigner16 把设计图导出成图片
1. 用鼠标选择要导出的对象,必须先选择. 2. 选择Edit—>Export Image 导出为你需要的格式图片,见下图:
- 「6月雅礼集训 2017 Day10」perm(CodeForces 698F)
[题目大意] 给出一个$n$个数的序列$\{a_n\}$,其中有些地方的数为0,要求你把这个序列填成一个1到$n$的排列,使得: $(a_i, a_j) = 1$,当且仅当$(i, j) = 1$.多 ...
- 表单元素(form、文本、按钮、选择)
表单元素 一.form form代表表单,功能:用于申明表单,定义采集数据的范围,也就是<form>和</form>里面包含的数据将被提交到服务器或者电子邮件里.<for ...
- Little Mathematics Knowledge 数学小常识
The sum of arithmetic sequence The sum of geometric sequence A special formula : n·n! = (n+1)! - n! ...
- margin 居中
左右auto加个宽度.margin-left: auto; margin-right: auto; width:640px;
- bzoj 1965 数学
首先我们可以发现每张牌的对应关系,假设序号为x的牌,经过一次洗牌后的位置为: 2*x x<=n/2 2*(x-n/2)-1 x>n/2 那么我们可以将下面的式子化简,变成2*x-n ...
- Linux二进制代码的阅读
大多数时候,我们研究的是如何阅读源代码.但在一些情况下,比如源代码不公开 或得到源代码的代价很高的情况下,我们又不得不需要了解程序的行为,这 时阅读二进制文件就非常重要.假设现在有一个二进制可执行文件 ...