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 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.
思路:
贪心,排序。
实现:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; struct node
{
int a, b;
};
node t[];
int n, k;
bool cmp(const node & x, const node & y)
{
if (x.a >= x.b && y.a >= y.b)
{
return x.a - x.b < y.a - y.b;
}
else if (x.a < x.b && y.a >= y.b)
{
return true;
}
else if (x.a >= x.b && y.a < y.b)
{
return false;
}
else
{
return x.b - x.a > y.b - y.a;
} }
int main()
{
cin >> n >> k;
for (int i = ; i < n; i++)
{
scanf("%d", &t[i].a);
}
for (int i = ; i < n; i++)
{
scanf("%d", &t[i].b);
}
sort(t, t + n, cmp);
int sum = ;
for (int i = ; i < n; i++)
{
if (i < k)
{
sum += t[i].a;
}
else
{
sum += min(t[i].a, t[i].b);
}
}
cout << sum << endl;
return ;
}
CF779C(round 402 div.2 C) Dishonest Sellers的更多相关文章
- 【贪心】Codeforces Round #402 (Div. 2) C. Dishonest Sellers
按照b[i]-a[i],对物品从大到小排序,如果这个值大于零,肯定要立刻购买,倘若小于0了,但是没买够K个的话,也得立刻购买. #include<cstdio> #include<a ...
- 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)
Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...
- 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看了看,不会,弃 ...
- 【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding
暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=1 ...
- Codeforces Round #402 (Div. 2) 题解
Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...
- Codeforces Round #402 (Div. 2) C
Description Igor found out discounts in a shop and decided to buy n items. Discounts at the store wi ...
随机推荐
- magento导入数据的方法
导入演示数据 分两种情况处理. 如果你是用composer方式安装的 非常简单,二行命令搞定:在项目根目录下执行.我们的是在/var/www/magento2/下面. 安装演示数据 php bin/m ...
- unity3d 公告板
Unity 自带具有一个平面的原始对象,但一个简单的平面在2D游戏或GUI可能是有用的,在任何情况下作出一个好的开始例子.一个最小的平面包含四个顶点,界定两个三角形的边角. 第一件事就是设置顶点数组. ...
- InstallShield 12 豪华版+破解版 下载
InstallShield 12 豪华版+破解版 下载 2009-07-09 19:18:30| 分类: 默认分类|字号 订阅 InstallShield 12 豪华版+破解版 下载 下载方 ...
- java io流中怎么在一个文本中追加字符串
1/ FileOutputStream(File file, boolean append)2/FileWriter(File file, boolean append) 不管哪一种IO都有 appe ...
- BZOJ3996 线性代数
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3996 转化题目给的条件 $$D = \sum_{i=1}^n \sum_{j=1}^n{A(i ...
- 任务29:自己动手构建RequestDelegate管道
cmd创建一个控制台应用程序 dotnet new console --name MyPipeline 用VSCode打开这个项目 新建类RequestDelegate.cs的类文件复制Program ...
- $(function() {}),即$(document).ready(function(),什么时候执行?以此为准
$(function() { //执行操作 }); $(function() {}) 是$(document).ready(function()的简写. 这个函数什么时候执行的呢? 答案:DOM加载完 ...
- bzoj 1076: [SCOI2008]奖励关【状压dp+概率dp】
设f[i][s]为前i步,选的礼物集合为s的方案数,然而并不会转移-- 看了hzwer的blog,发现要倒着转移,然后答案就是f[1][0] 妙啊 #include<iostream> # ...
- thinkphp5 +elasticsearch
php7使用elasticsearch 1.安装 官网下载地址:https://www.elastic.co/downloads/elasticsearch # 解压到非root目录,运行时使用非ro ...
- spring-data-redis 使用过程中踩过的坑
spring-data-redis简介 Spring-data-redis是spring大家族的一部分,提供了在srping应用中通过简单的配置访问redis服务,对reids底层开发包(Jedis, ...