平常水题 — Codeforces Round #415 (Div. 2) B. Summer sell-off (贪心 + 错误总结)

美国5435家医院CMS星级质量评级数据集 本数据集基于美国CMS官办的医院质量比较数据库整理加工,覆盖美国56个州和地区的5435家医院,每条记录包含53个字段。数据以医院名录为基础,融合质量评级与衍生分析字段:既有医院名称、地址、所在县州、邮编、电话等基础信息,也包含医院类型、所有制类型、是否提供急诊服务等分类属性,核心是官方发布的总体星级评级与死亡相关指标表现统计(更好、无差异、更差三类计数及脚注),并额外提供所有制分组、急症护理与产科友好标识、评级分档、指标覆盖率、更好更差比率、净指标得分、高评级标记以及各院在本州医院中的占比等衍生字段。其中3166家医院拥有总体评级,4501家提供急诊服务。适用人群:医疗政策研究者、卫生统计分析师、医疗质量管理人员、公共卫生专业师生以及数据科学爱好者。使用场景:适合开展医院质量与所有制关系研究、各州医疗资源与评级分布对比、急诊服务覆盖缺口分析、评级影响因素建模与预测、医院地理分布与可达性研究等课题。其他说明:文件为CSV格式,附带数据字典与说明文档,字段规整、注释完备,可直接导入Python、R、Excel、PowerBI等工具使用,适合课程作业、毕业设计与商业演示,也可作为医疗领域数据仓库建模的入门样例。 立即下载
B. Summer sell-off
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.

Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.

For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out.

Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem.

Input
The first line contains two integers n and f (1 ≤ n ≤ 105, 0 ≤ f ≤ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.

Each line of the following n subsequent lines contains two integers ki, li (0 ≤ ki, li ≤ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day.

Output
Print a single integer denoting the maximal number of products that shop can sell.

Examples
input
4 2
2 1
3 5
2 3
1 5
output
10
input
4 1
0 2
0 3
3 5
0 6
output
5
Note
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.

In the second example it is possible to sell 5 products, if you choose third day for sell-out.


题意:先输入n,f,分别代表有 n 天,可以让任意 f 天的的物品数量翻倍。接下来有n行,第 i 行有两个数 ki,li,分别代表在第 i 天有  ki  件物品,有 li 个顾客。每个顾客都会买一件物品。问 n 天后最多卖出多少件物品。


错误思路:一开始写是先把每天的物品翻倍后,求出这一天最多能卖出多少件后记录并从大到小排序。选取前f大的天数并标记前f大的天数。最后加上没被标记的天不翻倍最多能卖出多少件。这个思路是错误的,因为要求的是在原先不翻倍的基础上,任意f天翻倍后最多能增加卖出的件数。如这组数据

2     1

2     4

100 101

按照我的错误算法得到的答案是103,而实际正确的答案是104。


正确思路:1  当天的存货量大于等于需求量的时候,这一天的存货量是不需要翻倍的
     2  当天存货量小于需求量的时候,先让这一天的存货量翻倍,求出当天 ”可增加“ 的销售量
         然后根据可增加的销售量从大到小排序,选出前f天。


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

const int maxn = 1e5 + 5;

long long k[maxn],l[maxn],s[maxn];

long long cmp(long long a,long long b){
	return a > b;
}

int main(){
	int n,f;
	long long ans = 0,sum;
	scanf("%d %d",&n,&f);
	for(int i = 1;i <= n;i++){
		scanf("%I64d %I64d",&k[i],&l[i]);
		if(l[i] > k[i]){
			if(2 * k[i]  <= l[i]) s[i] = k[i];
			else s[i] = l[i] - k[i];
		}
		else{
			s[i] = 0;
			k[i] = l[i];
		}
	}
	sort(s + 1,s + n + 1,cmp);
	for(int i = 1;i <= f;i++) ans += s[i];
	for(int i = 1;i <= n;i++) ans += k[i];
	printf("%I64d",ans);
}

战国BC401年世界历史地图矢量文件SHP格式.zip 本资源为《战国BC401年世界历史地图矢量文件SHP格式》压缩包,文件大小约 2.26 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。 立即下载

相关推荐

早期颠覆性技术商业化加速:政府主导体系搭建步骤与路径.docx

早期颠覆性技术商业化加速:政府主导体系搭建步骤与路径

平常水题 - Sheldon Numbers(逆向思维,位运算)

Sheldon Numbers According to Sheldon Cooper, the best number is 73. In his own words, “The best number is 73. 73 is the 21st prime number. Its mirror, 37, is the 12th, and its mirror, 21, is the pr

dreams___的博客 1181

科技服务机构促成校企合作时,需遵循哪些规范化操作流程?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

AT - Grand - 004 - B - Colorful Slimes(思维理解)

B - Colorful Slimes Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come...

dreams___的博客 936

RTKLIB中RTK定位原理(一)

1 模型 1.1 非差观测值 非差观测值与RTKLIB中PPP定位原理——观测模型部分中一致。 1.2 单间单差观测值 若两个接收机距离较近,经过站间单差,电离层对流层延迟可消除,卫星s的钟差以及初始相位被消除,中依然包含接收机初始相位。 1.3 站间星间双差观测值 经过站间星间双差,接收机钟差及初始相位被消除。 2 EKF参数估计 2.1 EKF法则 EKF法则与RTKLIB中PPP定位原理——观测模型部分中一致。 2.2 状态变量与时间更新 (1)状态变量 在RTK...

papunzal的博客 3825

Zemax热分析实战:5分钟搞定双胶合透镜温度漂移优化(附操作数详解)

本文详细解析了使用Zemax进行光学系统热分析的全流程,以双胶合透镜为例,重点阐述了如何通过多重结构编辑器模拟温度变化,并利用关键操作数优化系统以抵抗温度漂移。文章提供了从基础设置到高级优化的实战技巧,帮助工程师快速掌握无热化设计方法,确保系统在宽温范围内保持稳定成像性能。

n4o5p6q7r的博客 405

平常水题 - 蚂蚁(栈的使用)

蚂蚁 Time limit per test: 0.5 seconds Time limit all tests: 5.0 seconds Memory limit: 256 megabytes 水平线上有 N 只蚂蚁,每只蚂蚁的位置及大小均不同。他们沿着 X 轴爬行,有的向左,有的向右,爬行的速度是一样的,两只蚂蚁相遇大一点的会吃掉小的。 现在从左到右给出每只蚂蚁的大小和爬行的

dreams___的博客 891

ARTIX-7 GTP 3G-SDI 工程构建与调试实战

本文详细介绍了基于ARTIX-7 FPGA和GTP收发器的3G-SDI工程构建与调试实战。从基础概念解析到Vivado工程创建、GTP IP核配置、SDI IP核集成,再到系统集成与时钟域处理,提供了全面的技术指导。文章还分享了调试技巧、常见问题排查方法以及性能验证步骤,帮助开发者快速掌握3G-SDI视频传输技术的实现与优化。

weixin_30443813的博客 264

平常水题 - J. Architect of Your Own Fortune (二分图匹配)

J. Architect of Your Own Fortune Vasya is a schoolboy who rides a trolley bus and then a bus to get to school. He’s always very happy to get a “lucky ticket,” which means the total of the first thre

dreams___的博客 880

AD936x Evaluation Software 实战配置指南:从寄存器设置到滤波器优化

本文提供AD936x Evaluation Software的实战配置指南,详细解析从工程创建、RF向导与时钟模块配置,到数字滤波器优化、数字接口设置及增益控制的完整流程。重点分享寄存器设置、滤波器系数权衡及PLL稳定技巧等核心要点,帮助开发者高效配置AD9361/AD9363射频芯片,快速应用于SDR、基站等场景。

perl8的博客 710

YOLOv8有效涨点,增强型 YOLOV8 与多尺度注意力机制特征融合,附代码,详细步骤

在本实验中,我们通过将双层路由注意(BRA)、广义特征金字塔网络(GFPN)和第四检测头结合到YOLOv8中,开发了一种新颖的BGF-YOLO架构。BGF-YOLO 包含注意力机制,可以更多地关注重要特征,特征金字塔网络可以通过将高级语义特征与空间细节合并来丰富特征表示。此外,我们研究了不同的注意力机制和特征融合、检测头架构对检测准确性的影响。实验结果表明,与YOLOv8x相比,BGF-YOLO的mAP50增加了4.7%。

kay_545 3053

寒武纪重现(HDU)- 1008(6261) - Rikka with Mutex(二分 + 错误总结)

Rikka with Mutex Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 32 Accepted Submission(s): 12 Problem Description Sometimes, technica...

dreams___的博客 857

基于Simulink的新能源汽车热管理系统设计与仿真详细介绍

新能源汽车(如纯电动汽车和混合动力汽车)的热管理系统是确保电池、电机和电控系统高效运行的关键。通过合理设计热管理系统,可以提高车辆的续航里程、延长电池寿命并提升整体性能。以下是如何在 MATLAB 和 Simulink 中设计并仿真一个新能源汽车热管理系统的详细步骤。通过上述步骤,我们成功设计并实现了基于 Simulink 的新能源汽车热管理系统。该系统能够根据目标温度和实际反馈,通过 PID 控制器或模糊控制器调整冷却液流量、风扇转速等参数,实现对电池、电机和车内的精确温度控制。

xiaoheshang_123的博客 391

平常水题 - Atcoder 058 - C - 怪文書 / Dubious Document(字符串的处理)

C - 怪文書 / Dubious Document                                                       Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snuke loves "paper cutting": he c

dreams___的博客 808

5G RF前端架构为什么越来越复杂?从8天线、MIMO、ET、DRX到ACLR/EVM彻底拆开

AdjacentChannelLeakageRatioAdjacentChannelLeakageRatio主信道的功率,有多少泄漏到了隔壁Channel。ACLRPAdjacentPMainACLR=ACLRPMain​PAdjacent​​通常以dBc表达。

weixin_43199439的博客 57

在 SAP Fiori 中正确配置 Group 角色:从 PFCG 分配到首页呈现的完整链路

摘要:SAP Fiori项目中,用户登录后能否看到应用往往取决于角色配置而非前端开发。关键在于通过PFCG角色将launchpad designer中创建的tile group关联到用户角色。Catalog是应用池,group是用户首页可见的工作区。正确配置后,用户会看到角色对应的默认分组,同时保留个性化调整能力。项目实施中常见问题是应用开发完成但未正确配置group与角色关联,导致业务用户无法在首页看到应用入口。(150字)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 174

CF - div2 - 459 - C - The Monster

C. The Monster time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output As Will is stuck in the Upside Down, he can still communicate with his mom,

dreams___的博客 794

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

D. Almost Identity Permutations(dp)

D. Almost Identity Permutations time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A permutation p of size n is an array such that every inte

dreams___的博客 773

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

2017中国大学生程序设计竞赛-哈尔滨站 (B.尺取 + 二分)

Problem Description Alice are given an array A[1..N] with N numbers.Now Alice want to build an array B by a parameter K as following rules:Initially, the array B is empty. Consider each interval in ar

dreams___的博客 740

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

AtCoder - Petrozavodsk - Contest - 001 - D (缩点 + 贪心 + 错误总结)

D - Forest Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem Statement You are given a forest with N vertices and M edges. The vertices are numbered 0 through N−1. The edges are

dreams___的博客 694

B. Preparing for Merge Sort(二分)

2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)B. Preparing for Merge Sort time limit per test2 seconds memory limit per

dreams___的博客 665

平常水题 - atcoder 062 - D - 3N Numbers

D - 3N Numbers Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Let N be a positive integer. There is a numerical sequence of length 3N, a=(a1,a2,…,a3N). Snuke

dreams___的博客 639

平常水题 - CodeForces - 703C(二分 + 几何)

C. Chris and Road time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output And while Mishka is enjoying her trip...

dreams___的博客 627

平常水题 - CodeForces - 222B

The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.

dreams___的博客 600

Problem G. Rectangular Polygon(dp + 转移重现)

2006-2007 Winter Petrozavodsk Camp, Andrew Stankevich Contest 23 (ASC 23)Problem G. Rectangular Polygon Input file: polygon.in Output file: polygon.out Time limit: 1 second Memory limit: 64 megabyt

dreams___的博客 543
上一篇: map 数组里放 pair 或 结构体
下一篇: Codeforces Round #427 (Div. 2) C (前缀和思想)
dwenhu___
博客等级 码龄10年 8粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值