Codeforces Round #251 (Div. 2) 439D Devu and his Brother(脑洞)

Open3D 点云DBSCAN聚类算法 DBSCAN(Density-Based Spatial Clustering of Applications with Noise)是一种基于密度的聚类算法,能够识别任意形状的聚类,并处理噪声数据。 阅读详情

D. Devu and his Brother
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and bby their father. The array a is given to Devu and b to his brother.

As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.

Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.

You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.

Input

The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105). The second line will contain n space-separated integers representing content of the array a (1 ≤ ai ≤ 109). The third line will contain m space-separated integers representing content of the array b (1 ≤ bi ≤ 109).

Output

You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.

Sample test(s)
input
2 2
2 3
3 5
output
3
input
3 2
1 2 3
3 4
output
4
input
3 2
4 5 6
1 2
output
0
Note

In example 1, you can increase a1 by 1 and decrease b2 by 1 and then again decrease b2 by 1. Now array a will be [3; 3] and array bwill also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.

In example 3, you don't need to do any operation, Devu's condition is already satisfied.




给定a数组和b数组,两数组的元素每次可以增减1,要求增减最少使得a数组中最小数大于等于b数组最大数。


把a,b数组都存到c数组中,c[m]即为最终那个数,然后一个一个加起来就是答案。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int maxn = 1e5 + 5;
typedef long long ll;
int main(int argc, char const *argv[])
{
	int n, m;
	while(scanf("%d%d", &n, &m) != EOF) {
		ll a[maxn], b[maxn], c[maxn * 2];
		for(int i = 0; i < n; ++i) {
			scanf("%lld", &a[i]);
			c[i] = a[i];
		}
		for(int j = 0; j < m; ++j) {
			scanf("%lld", &b[j]);
			c[j + n] = b[j];
		}
		sort(c, c + m + n);
		ll ans = 0, t = c[m];
		for(int i = 0; i < n; ++i)
			ans += max((ll)0, t - a[i]);
		for(int i = 0; i < m; ++i)
			ans += max((ll)0, b[i] - t);
		printf("%lld\n", ans); 		
	}
	return 0;
}


第 10 篇:深度学习的“军火库”——CNN、RNN与Transformer,AI如何看懂世界? 深度学习的革命,不是依赖单一的通用大脑,而是为不同任务打造了专属“军火库”:CNN用“局部感知”看懂图像,RNN用“循环记忆”理解序列,而Transformer则用“全局注意力”开启了AIGC时代。理解这些架构,不是记忆孤立的技术,而是洞察AI从“专才”走向“通才”的进化脉络。 阅读详情

相关推荐

DNF服务器搭建服务端架设教程

第三步:打开winscp,上传Script.pvf(版本)、publickey.pem(密钥)、df_game_r(等级补丁)到home/neople/game目录下。第四步:打开putty输入./stop,./stop(两次,如果是首次架设不用./stop),./run,运行刚才上传的三个游戏文件。③是本地配置登录器的配置文件,自动生成,可以删除,但是还是会根据你生成的登录器生成这个文件,类似日志。⑤密钥中所上传的三个文件其中之一,重中之重,上传到服务器的密钥必须和登录器中的密钥为一个。

V13807970340的博客 6280

CodeForces - 439D Devu and his Brother 思维+排序

题意:给出数列a,b。可以对每个数进行操作+1或者-1。求最小的操作数使得a数列的最小值,大于b数列的最大值。 题解:首先取出a数列的最小值x与b数列的最大值y进行操作(只是保证满足题意,取min(n,m)对x,y)。最少的操作肯定就是变到同一个数c(c是任意的),那么有ans=(y-c)+(c-x)=y-x。这个最终的c介于这么多对的x,y之间。

ACZone 528

AXI4接口说明

ACLK:全局AXI接口时钟输入(建议与系统时钟保持一致)ARESET_n:全局AXI接口复位信号,低电平有效。PS:在HBM AXI接口应用中,此复位端口仅应在数据传输开始前使用。若在传输开始后使用,会导致AXI接口与内存控制器失步(out-of-sync)。当开关启用时,IP核会将所有ARESET_n引脚内部连接在一起——因为内存作为一个整体工作。

rhtul的博客 1528

D. Devu and his Brother(思维+三分)

https://codeforces.com/problemset/problem/439/D 思路:不是很能想到贪心阿。但是看这个范围。感觉像二分枚举。 首先定一个假设最终到达的值为temp。那么可以得出Ans=Σtmp-a【i】(a【i】<tmp)+Σb【i】-tmp(b【i】>tmp); 答案在temp+1/+2/-1/-2都会变大。是个单峰函数。 于是上三分 #include<iostream> #include<vector> #include&lt

代码笔记本 218

告别龟速计算!用Python的fengwo模块5分钟搞定通达信COST/WINNER函数(附完整代码)

本文介绍如何使用Python的fengwo模块高效复现通达信的COST和WINNER函数,解决量化交易中的计算精度和性能问题。通过C++核心算法和多线程优化,计算速度提升显著,误差低于0.5%,并支持与通达信DLL无缝集成,适用于实盘交易策略开发。

weixin_42533751的博客 606

EDA公司(一):Synopsys-- 主要 EDA 工具及其简介

Synopsys 是一家领先的电子设计自动化(EDA)软件公司,提供了一系列全面的产品和服务,旨在支持从概念设计到大规模生产的各个阶段。Synopsys 的 EDA 工具覆盖了芯片设计的各个方面,包括但不限于逻辑综合、静态时序分析、功能验证、物理实现、形式验证、测试插入、电源分析、信号完整性分析等。

MHD0815的博客 3321

Codeforces Round #251 (Div. 2)-D. Devu and his Brother

原题链接 D. Devu and his Brother time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu and his brother love

L. 420

手把手教学:利用AutoDL与vLLM快速部署DeepSeek-R1大模型实战指南

本文详细介绍了如何利用AutoDL平台和vLLM框架快速部署DeepSeek-R1大模型的实战指南。从服务器配置、vLLM安装优化到模型部署的两种方案,再到性能调优和生产环境建议,手把手教你高效完成大模型部署。特别针对国内开发者遇到的网络问题提供了稳定解决方案,并分享了显存优化、磁盘清理等实用技巧。

weixin_42531779的博客 332

Codeforces 439D Devu and his Brother(排序)

题目链接:Codeforces 439D  Devu and his Brother 题目大意:Devu和他的哥哥互相深爱着对方,我确信他们是搞基的,为此我还去查了一下Devu是男人名还是女人名,但是后来发现His Brother,所以可以证明,他们就是搞基的。题目很简单,父亲给了他们两个人分别一个数组。但是Devu希望自己最小的数都可以不必哥哥最大的数小,现在对数组中的数有两种操作,一

不慌不忙、不急不躁 1872

手把手教你学基带SOC芯片(4.4.9)--基带芯片的电源管理实例:高通 Snapdragon 系列实例(十)

Snapdragon 888 通过支持多种深度睡眠模式,如 AOAC 模式、低功耗模式和深度睡眠模式,以及智能电源管理技术,实现了对功耗的精细管理。这些模式不仅延长了设备的电池寿命,还确保了用户在各种使用场景下的良好体验。无论是保持网络连接、限制后台活动,还是完全关闭不必要的功能,Snapdragon 888 都能够灵活应对,提供高效的功耗管理方案。

MHD0815的博客 745

在 SAP S/4HANA Public Cloud 中,用 RAP 一键生成 PDF 并在 Fiori 前端触发下载的完整方案

create;update;delete;// 生成并返回当前文档上下文。

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

CF 439D(251D题)Devu and his Brother

Devu and his Brother time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu and his brother love each other a lot. As th

墨守空城与钟楼 2974

C# WinForm上位机:从串口调试工具到智能温控系统(Modbus RTU协议实战+完整源码)

做工业上位机开发时,我们常从串口调试工具入手:验证设备通信、查看数据帧,但面对实际场景(比如温控、电机控制),单纯的“收发数据”远远不够——需要解析工业标准协议(如Modbus RTU)、实时监控关键指标、实现自动化控制逻辑,还要有稳定的UI交互和数据记录。串口调试工具能收发数据,但看不懂Modbus RTU帧(地址、功能码、寄存器、CRC校验);想控制温控设备(如加热器、风扇),但不知道如何通过Modbus写入控制指令;手动调节目标温度时,温度波动大,需要PID算法实现精准控温,但不会集成;

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1313

Codeforces Round #251 Div2D 439D Devu and his Brother 二分查找STL

很水的题目……我交了四次。 注意到

KuribohG 1597

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Codeforces Round #251(Div. 2) 439D. Devu and his Brother 枚举

D. Devu and his Brother time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu and his brother love each other

Jonariguez 吾本优秀 548

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Codeforces Round #251(Div. 2) 439A. Devu, the Singer and Churu, the Joker 水题

A. Devu, the Singer and Churu, the Joker time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu is a renowned

Jonariguez 吾本优秀 999

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round #251 (Div. 2) 439B Devu, the Dumb Guy(贪心)

B. Devu, the Dumb Guy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu is a dumb guy, his learning curve

GKHack's Blog 1141

【索引】Codeforces Round #251 (Div. 2)

Problem A: Devu, the Singer and Churu, the Joker(439A)

不慌不忙、不急不躁 849

Codeforces Round #251(Div. 2) 439B. Devu, the Dumb Guy 贪心

B. Devu, the Dumb Guy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu is a dumb guy, his learning curve

Jonariguez 吾本优秀 711

[Codeforces Round #195 DIV2D (CF336D)] Vasily the Bear and Beautiful Strings

题意一个01串,给定0的个数n,1的个数m,询问多少个不同01串通过不断进行一种操作后得到一个字符g(0或1) 操作如下: 将01串最后两个数字取出,如果两个都是0,则在01串末尾放回1,否则放回0,直到01串只剩1个字符 给出n,m,g题解首先n或m为0的情况单独处理。 下面思考如下规律(===代表任意非空01串) 1=== ans:0 1 ans:1 01===

ztx 487

439 D. Devu and his Brother

/* 简单三分法解决,也可以排序后简单贪心. */ #include #include #include using namespace std; const int maxn = 100000 + 100; #define LL long long int n,m; LL a[maxn],b[maxn]; bool cmp(int a,int b) { return a>b;

\*zyeric*/ 541

Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)

题目链接: 第一行给你n、m,接下来的一行有n个数,如果为1则代表这个点有cat,接下来的n-1行每行给出x、y,表示x、y相连。问你从1出发 能到达的叶子结点有几个,要求到达叶子结点的路上连续有cat的点不超过m。 a数组保存结点是否含有cat,从1这个点开始dfs,每次dfs对cat数组操作,记录连续的含有cat的点数,回溯时再判断当前结点是否满足 条件,要求结点为叶子

GKHack's Blog 2042

Codeforces Round #200 (Div. 2)344E Read Time(二分)

E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike does not use slow hard disks

GKHack's Blog 1750

Codeforces Round #325 (Div. 2) 586ABC题解

题目链接:点击打开链接 A: 给出Alena的课表, 1代表有课, 0代表没课, 2个连续0以上可以回家休息, 问你一天在学校待多久. 直接模拟即可, 可以直接计算1, 101的数目. 我记录了开头的1和结尾的1, 然后减去2个连续0以上的个数就是答案. AC代码: #include "iostream" #include "cstdio" #include "cstring" #

GKHack's Blog 1711

Codeforces Round #308 (Div. 2)题解

第二天补的 并不都是自己写的 参考了别人的题解 感觉这次cf题意好懂 就是做起来嘛。。 毕竟我还太弱。。 只为落实 A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input

GKHack's Blog 1675

Codeforces Round #322 (Div. 2) 581A 581B 581C

581A链接:点击打开链接 给你a只红袜子,b只蓝袜子,问你可以组成多少对颜色不同的袜子以及剩下多少对单色袜子。 小小的脑洞,答案分别为a, b最小值以及a - b绝对值的一半。 AC代码: #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" using na

GKHack's Blog 1666
上一篇: Codeforces Round #259 (Div. 2) 454A Little Pony and Crystal Mine(模拟)
下一篇: POJ1745 Divisibility(dp)
GKHack
博客等级 码龄12年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值