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 < ...
随机推荐
- pandas关联mysql并读写数据库
1.代码读写mysql,必须安装关联mysql的工具 操作如下命令: sudo apt-get install mysql-server mysql-clientsudo apt-get instal ...
- Python3 简单封装 sqlite3 - SimpleToolSql
#coding: utf-8 #Author:boxker #Mail:icjb@foxmail.com import sqlite3 import os class simpleToolSql(): ...
- 如何使用jmeter做关联
1.适用场景 从上一个接口的返回值中获取值传递给下一个接口使用 2.添加JSON Extractor 在需求提取的参数上添加--后置处理器--JSON Extractor 从登录接口的返回值中取use ...
- tab key usage
QA:gvim编辑ascii文本时由于tabkey的default setting 不合适编写Verilog代码(比如一个tab 代表多少空格) ANS: 1.tab 的自动补齐有两种usage自动补 ...
- scanf(),gets(),getchar()
scanf()与gets()区别: scanf( )函数和gets( )函数都可用于输入字符串,但在功能上有区别.若想从键盘上输入字符串"hi hello",则应该使用gets() ...
- BZOJ 4027: [HEOI2015]兔子与樱花
贪心 #include<cstdio> #include<algorithm> using namespace std; int cnt,n,m,F[2000005],c[20 ...
- Makefile基础(二)
上一章:C语言之Makefile基础(一) 上一章的Makefile写的中规中矩,比较繁琐,是为了讲清楚基本概念,其实Makefile有很多灵活的写法,可以写的更简洁,同时减少出错的可能 一个目标依赖 ...
- luogu3390 【模板】矩阵快速幂
#include <iostream> #include <cstdio> using namespace std; typedef long long ll; ll k; c ...
- Leetcode25--->Reverse Nodes in k-Group(以k个节点为段,反转单链表)
题目: 给定一个单链表,一次反转k个节点,最终返回翻转后的链表的头节点:如果链表不足k个,则不变 举例: Given this linked list: 1->2->3->4-> ...
- [转]Visual Studio调试之符号文件
http://www.cnblogs.com/killmyday/archive/2009/10/14/1582882.html 前面在不能设置断点的检查步骤和Visual Studio调试之断点进阶 ...