Codeforces Round #402 (Div. 2) C
Description
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个物品,下周买n-k个物品,问总的花费最小
解法:以为是dp,后来用贪心过了,我们先比较两个价格的变化,优先买价格变化小的(只能买当前价格),接下来买价格中最便宜的。
我们记录价格变化,从小到大排序,然后前k个数字相加,然后买价格最便宜的
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream> // C++头文件,C++完全兼容C
#include <algorithm> // C++头文件,C++完全兼容C
#define fre freopen("in.txt","r",stdin) //以文件代替控制台输入,比赛时很常用,能缩短输入测试样例的时间
#define INF 0x3f3f3f3f
#define inf 1e60
using namespace std; // C++头文件,C++完全兼容C
#define N 200005 // 宏定义
#define LL long long //宏定义 int a[N],b[N];
struct P
{
int x,y,ans;
}H[N];
int ans;
bool cmd(P a,P b)
{
return a.ans<b.ans;
} int main()
{
int n,k;
cin>>n>>k;
for(int i=;i<=n;i++)
{
cin>>H[i].x;
}
for(int i=;i<=n;i++)
{
cin>>H[i].y;
H[i].ans=H[i].x-H[i].y;
}
sort(H+,H++n,cmd);
for(int i=;i<=k;i++)
{
ans+=H[i].x;
} for(int i=k+;i<=n;i++)
{
ans+=min(H[i].x,H[i].y);
}
cout<<ans<<endl;
return ;
}
Codeforces Round #402 (Div. 2) C的更多相关文章
- 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
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) D. String Game
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...
- 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 ...
- 【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) 阵亡记
好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...
- CodeForces Round #402 (Div.2) A-E
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...
- Codeforces Round #402 (Div. 2) B
Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. ...
随机推荐
- Zip加密解密
Zip加密解密方法: 1.winzipaes http://blog.csdn.net/zhyh1986/article/details/7724229 2.zip4j http://blog.csd ...
- Eclipse搭建Web Service服务
1.建立动态Web工程(Dynamic Web Project),工程名为Server.编写类HelloWorld. package com.mysever; public class HelloWo ...
- C语言restrict关键字的使用----可以用来优化代码
C99中新增加了restrict修饰的指针:由restrict修饰的指针是最初唯一对指针所指向的对象进行存取的方法,仅当第二个指针基于第一个时,才能对对象进行存取.对对象的存取都限定于基于由restr ...
- dsp端编译异常之max和min未定义
(1)在函数之前 声明__stdcall 时 在linux 端或dsp端 linux 之前的加上宏定义 __stdcall是MS的编译器使用的只需要#define __stdcall定义一个宏就可以 ...
- LeetCode(11)题解: Container With Most Water
https://leetcode.com/problems/container-with-most-water/ 题目: Given n non-negative integers a1, a2, . ...
- DT的jquery
IE8浏览器,打开页面提示脚本错误,query不识别,缺少")"等等, 各种删除,最后只保留引用jquery文件还是不行,最后更好jquery为jQuery v1.12.4 版本, ...
- 关于hbase集群
1 一个hadoop data node上运行一个region server region server和data node在同一台机器上,这样就保证了数据的局部性. 2 hbase region s ...
- Client should know only resource URIs and that’s all.
REST Principles and Architectural Constraints – REST API Tutorial https://restfulapi.net/rest-archit ...
- poj 1742 Coins(二进制拆分+bitset优化多重背包)
\(Coins\) \(solution:\) 这道题很短,开门见山,很明显的告诉了读者这是一道多重背包.但是这道题的数据范围很不友好,它不允许我们直接将这一题当做01背包去做.于是我们得想一想优化. ...
- HDU 2444 The Accomodation of Students(判断二分图+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...