博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF 439D(251D题)Devu and his Brother
阅读量:6550 次
发布时间:2019-06-24

本文共 2306 字,大约阅读时间需要 7 分钟。

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 b by 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 22 33 5
Output
3
Input
3 21 2 33 4
Output
4
Input
3 24 5 61 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 b will 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.

贪心问题,代码不长,好看懂

AC代码例如以下:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define ll long long#define M 100005bool cmp(int a,int b){ return a>b;}int min(int a,int b){ return a
>n>>m; for(i=0;i
>a[i]; for(i=0;i
>b[i]; sort(a,a+n); sort(b,b+m,cmp); n=min(n,m); ll sum=0; for(i=0;i
a[i]) sum+=(ll)(b[i]-a[i]); } cout<
<

转载地址:http://louco.baihongyu.com/

你可能感兴趣的文章
ASM文件系统
查看>>
ajax学习笔记(原生js的ajax)
查看>>
mysql 函数 事务
查看>>
1312 连续自然数和
查看>>
进程/线程介绍
查看>>
SPSS-Friedman 秩和检验-非参数检验-K个相关样本检验 案例解析
查看>>
java UDP server
查看>>
Windows MongoDB安装配置
查看>>
大数据开发实战:Hive优化实战3-大表join大表优化
查看>>
Windows如何使用jstack跟踪异常代码
查看>>
js手动生成Json数据
查看>>
当Ucenter和应用通信失败,DZ数据库备份恢复
查看>>
Memcached
查看>>
项目启动前的准备工作(随笔一)
查看>>
海量Web日志分析 用Hadoop提取KPI统计指标
查看>>
“神一般存在”的印度理工学院到底有多牛?
查看>>
Hadoop2.2.0安装配置手册!完全分布式Hadoop集群搭建过程~(心血之作啊~~)
查看>>
《大话重构》
查看>>
一起谈.NET技术,WPF与混淆器
查看>>
一起谈.NET技术,C#面向对象设计模式纵横谈:Singleton 单件
查看>>