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 ...
随机推荐
- 170. Two Sum III - Data structure design
题目: Design and implement a TwoSum class. It should support the following operations: add and find. a ...
- WCF - Developers Tools
For developing a WCF service application, there are mainly two tools – Microsoft Visual Studio and C ...
- 浏览器编辑HTML
运行效果: 浏览器编辑HTML // test.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...
- Hadoop MapReduce 二次排序原理及其应用
关于二次排序主要涉及到这么几个东西: 在0.20.0 以前使用的是 setPartitionerClass setOutputkeyComparatorClass setOutputValueGrou ...
- Ubuntu 出现apt-get: Package has no installation candidate问题
今天在安装软件的时候出现了Package has no installation candidate的问题,如: # apt-get install <packagename> Read ...
- NOI2010海拔
2007: [Noi2010]海拔 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 1302 Solved: 612[Submit][Status] ...
- Git submodule实战
http://blog.jqian.net/post/git-submodule.html 使用git管理的项目开发中,如果碰到公共库和基础工具,可以用submodule来管理. 常用操作 例如, 公 ...
- 【转】win7 旗舰版激活密钥
原文网址:http://zhidao.baidu.com/question/1496641289562471179.html 旗舰版KH2J9-PC326-T44D4-39H6V-TVPBYTFP9Y ...
- 用PowerShell批量部署wsp包
转:http://www.xuebuyuan.com/168337.html 提供wsp部署的参数: $wsppath:wsp文件所在的路径,如"c:\" $wspnames:路径 ...
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
最近在学习RxJava 感觉很happy ,happy的同时遇到不少问题 没办法一点一点来 上张帅图先 在使用RxJava + Retrofit 的时候 有时候接口请求参数不规范 比如 {} @For ...