AC日记——Dishonest Sellers Codeforces 779c
2 seconds
256 megabytes
standard input
standard output
Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi.
Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.
Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items.
In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now).
The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week).
Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.
3 1
5 4 6
3 1 5
10
5 3
3 4 7 10 3
4 5 5 12 5
25
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
思路;
计算价值然后排序水过(至少k个不是共k个);
来,上代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> #define maxn 200005 using namespace std; struct SortNodeType {
int ai,bi,vi;
};
struct SortNodeType item[maxn]; int if_z,n,k,ans; char Cget; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} bool cmp(struct SortNodeType a,struct SortNodeType b)
{
if(a.vi!=b.vi) return a.vi<b.vi;
else
{
return a.ai<b.ai;
}
} int main()
{
in(n),in(k);
for(int i=;i<=n;i++) in(item[i].ai);
for(int i=;i<=n;i++)
{
in(item[i].bi);
item[i].vi=item[i].ai-item[i].bi;
}
sort(item+,item+n+,cmp);
int pos=;
for(int i=;i<=n;i++)
{
if(item[i].vi<=) pos++;
else break;
}
k=max(k,pos);
for(int i=;i<=k;i++) ans+=item[i].ai;
for(int i=k+;i<=n;i++) ans+=item[i].bi;
cout<<ans;
return ;
}
AC日记——Dishonest Sellers Codeforces 779c的更多相关文章
- AC日记——Cards Sorting codeforces 830B
Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Card Game codeforces 808f
F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...
- AC日记——Success Rate codeforces 807c
Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——T-Shirt Hunt codeforces 807b
T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Magazine Ad codeforces 803d
803D - Magazine Ad 思路: 二分答案+贪心: 代码: #include <cstdio> #include <cstring> #include <io ...
- AC日记——Broken BST codeforces 797d
D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...
- AC日记——Array Queries codeforces 797e
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...
- AC日记——Maximal GCD codeforces 803c
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...
- AC日记——Vicious Keyboard codeforces 801a
801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...
随机推荐
- vim小操作
初时,先有ed,ed为ex之父,ex为vi之父,而vi为vim之父 c 修改 d 删除 y 复制到寄存器 g~ 反转大小写 gu 反转为小写 gU 反转为大写 > 增加缩进 < 减小缩进 ...
- Python中的列表(1)
1.什么是列表? 列表是由一组按特定顺序排列的元素组成. 2.如何表示? 在Python中用方括号([ ])来表示列表.栗子如下: contries = ['China','England','Fra ...
- QT添加自定义信号后编译出现undefined reference
QT添加自定义信号后编译出现undefined reference 这是需要重新生成qmake: build --->run qmake
- gcc——预处理(预编译),编译,汇编,链接
一,预编译 操作步骤:gcc -E hello.c -o hello.i 主要作用: 处理关于 “#” 的指令 [1]删除#define,展开所有宏定义.例#define portnumber 333 ...
- http请求原理
客户端发送一个HTTP请求到服务器的请求消息包括以下格式:请求行(request line).请求头部(header).空行和请求数据四个部分组成,下图给出了请求报文的一般格式. 请求行 HTTP响应 ...
- UVA - 1220 Party at Hali-Bula (树形DP)
有 n 个员工,n-1个从属关系. 不能同时选择某个员工和他的直接上司,问最多可以选多少人,以及选法是否唯一. 树上的最大独立集问题.只不过多了一个判断唯一性. dp[u][0]表示不选这个点的状态, ...
- Elasticsearch安装---安装运行es
1.进入到elasticsearch cd /data/webroot/www/elasticsearch/elasticsearch-5.6.3 2.运行:sh ./bin/elasticsearc ...
- luogu3203 [HNOI2010]弹飞绵羊
lct裸题 #include <iostream> #include <cstdio> using namespace std; int n, ski[200005], m, ...
- concurrent.futures模块(进程池&线程池)
1.线程池的概念 由于python中的GIL导致每个进程一次只能运行一个线程,在I/O密集型的操作中可以开启多线程,但是在使用多线程处理任务时候,不是线程越多越好,因为在线程切换的时候,需要切换上下文 ...
- Set容器——TreeSet及常用API
TreeSet及常用Api ① TreeSet为使用树来进行存储的Set接口提供了一个工具,对象按升序存储,访问和检索很快; ② 在存储了大量的需要进行快速检索的排序信息的情况下,TreeSe ...