Codeforces 439D Devu and his Brother 三分
题目链接:点击打开链接
= - =曾经的三分姿势不对竟然没有被卡掉,,,太逗。。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define M 200004
#define N 100040
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define Mid(x,y) ((x+y)>>1)
#define ll __int64
#define Sum(x) tree[x].sum
#define Mod(x) tree[x].mod
#define inf 1000000000
ll n,m;
ll a[N],b[N];
ll ok(ll x){
ll ans = 0;
for(ll i = 1; i <= n; i++)if(x>a[i])ans+=(x-a[i]);
for(ll i = 1; i <= m; i++)if(x<b[i])ans+=(b[i]-x);
return ans;
}
int main(){
ll i,j,u,v;
while(~scanf("%I64d %I64d",&n,&m)){
ll minn = inf, maxx = 0;
for(i=1;i<=n;i++)scanf("%I64d",&a[i]), minn = min(minn,a[i]);
for(i=1;i<=m;i++)scanf("%I64d",&b[i]), maxx = max(maxx,b[i]);
if(minn>=maxx){puts("0");continue;}
ll ans = inf;
ll l = minn, r = maxx;
ans = min(ok(l),ok(r));
while(l<r){
ll mid1 = (l+r)/2, mid2 = (mid1+r)/2;
ll tmp1 = ok(mid1), tmp2 = ok(mid2);
if(tmp1>tmp2)
l = mid1;
else r = mid2;
ans = min(ans, min(tmp1, tmp2));
}
printf("%I64d\n",ans);
}
return 0;
}
/*
2 2
2 3
3 5
3 2
1 2 3
3 4
3 2
4 5 6
1 2 */
Codeforces 439D Devu and his Brother 三分的更多相关文章
- codeforces 251 div2 D. Devu and his Brother 三分
D. Devu and his Brother time limit per test 1 second memory limit per test 256 megabytes input stand ...
- codeforces 439D Devu and Partitioning of the Array(有深度的模拟)
题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...
- 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 ...
- Codeforces 451E Devu and Flowers(容斥原理)
题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...
- Codeforces 439C Devu and Partitioning of the Array(模拟)
题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数 ...
- Codeforces C. Elections(贪心枚举三分)
题目描述: C. Elections time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round#251(Div 2)D Devu and his Brother
--你以为你以为的.就是你以为的? --有时候还真是 题目链接:http://codeforces.com/contest/439/problem/D 题意大概就是要求第一个数组的最小值要不小于第二个 ...
- codeforces#439 D. Devu and his Brother (二分)
题意:给出a数组和b数组,他们的长度最大1e5,元素范围是1到1e9,问你让a数组最小的数比b数组最大的数要大需要的最少改变次数是多少.每次改变可以让一个数加一或减一 分析:枚举a数组和b数组的所有的 ...
- Codeforces 791A Bear and Big Brother(暴力枚举,模拟)
A. Bear and Big Brother time limit per test:1 second memory limit per test:256 megabytes input:stand ...
随机推荐
- ActionBar官方教程(6)把图标变成一个返回到上级的按钮,同一个app间,不同app间,不同fragment间
Navigating Up with the App Icon Enabling the app icon as an Up button allows the user to navigate yo ...
- tlplayer,wzplayer支持wince,winphone,windows8 for arm
tlplayer,wzplayer宣布支持wince,winphone,windows8 for arm,支持http,hls,rtmp,rtsp,mms等媒体流协议. 支持加密视频播放. 目前tlp ...
- php include include_once require require_once 的区别与联系
一.require 与 include 的区别: The require() function is identical to include(), except that it handles er ...
- java集合类——Stack类
查看java的API文档,Stack继承Vector类. 栈的特点是后进先出. API中Stack自身的方法不多,基本跟栈的特点有关. import java.util.Stack; public c ...
- addlinkedserver
http://blog.sina.com.cn/s/blog_5321db9d0100f89g.html --创建链接服务器 exec sp_addlinkedserver 'ITSV ', ' ' ...
- BZOJ_1617_[Usaco2008_Mar]_River_Crossing_渡河问题_(动态规划)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1617 FJ要把\(n\)头奶牛用船运到河对岸.FJ自己在船上要用\(m\)时间,如果运送\(i ...
- htmlparser源码简单分析
Htmlparser源代码分析 一.根目录下的类 1.Attribute.java 属性类,四个field:mName,mAssignment,mValue,mQuote; 空白标签时:mName=n ...
- haproxy配置直接重定向url
在邮件列表看到有个人问haproxy能否在接到一个请求时选择一个后端服务器,然后301重定向url .主要原因是他有5个1G的出口,这样就能充分利用其带宽.测试了一下是可以的 frontend fre ...
- Nginx、SSL双向认证、PHP、SOAP、Webservice、https
本文是1:1模式,N:1模式请参见新的一篇博客<SSL双向认证(高清版)> ----------------------------------------------------- 我是 ...
- C#索引器的作用及使用
1. 作用: 可以使得类和实例能够像数组那样使用一样,又称为带参属性 2. 区分 (1)索引器与数组的比较: 索引器的索引值不受类型限制.用来访问数组的索引值一定是整数,而索引器可以是其他类型的索引值 ...