题目链接:点击打开链接

= - =曾经的三分姿势不对竟然没有被卡掉,,,太逗。。

#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 三分的更多相关文章

  1. 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 ...

  2. codeforces 439D Devu and Partitioning of the Array(有深度的模拟)

    题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...

  3. 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 ...

  4. Codeforces 451E Devu and Flowers(容斥原理)

    题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...

  5. Codeforces 439C Devu and Partitioning of the Array(模拟)

    题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数 ...

  6. Codeforces C. Elections(贪心枚举三分)

    题目描述: C. Elections time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

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

    --你以为你以为的.就是你以为的? --有时候还真是 题目链接:http://codeforces.com/contest/439/problem/D 题意大概就是要求第一个数组的最小值要不小于第二个 ...

  8. codeforces#439 D. Devu and his Brother (二分)

    题意:给出a数组和b数组,他们的长度最大1e5,元素范围是1到1e9,问你让a数组最小的数比b数组最大的数要大需要的最少改变次数是多少.每次改变可以让一个数加一或减一 分析:枚举a数组和b数组的所有的 ...

  9. 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 ...

随机推荐

  1. 李洪强iOS开发本人集成环信的经验总结_02_基本配置

     李洪强iOS开发本人集成环信的经验总结_02_基本配置 来到APPdelegate中做一些配置 01 - 导入头文件 02 - 在didFinishLaunchingWithOptions用法总结 ...

  2. yii

    2008年出现的一个以php为基础的框架,特点是:高性能框架.代码重用性.速度非常快(改完代码后直接刷新就可以展示修改后的页面).有小物件.登录组件.日志组件等等. main.php配置与数据库相连的 ...

  3. SPRING IN ACTION 第4版笔记-第五章BUILDING SPRING WEB APPLICATIONS-002-Controller的requestMapping、model

    一.RequestMapping 1.可以写在方法上或类上,且值可以是数组 package spittr.web; import static org.springframework.web.bind ...

  4. JAVA与C++的区别和联系

    这篇总结的貌似不错: http://wenku.baidu.com/link?url=VixkWGl0BzUkmceaDJnQeUhzKEIex6poGaKKvMTP87P8a7HTmS5uIi87I ...

  5. POJ_2566_Bound_Found_(尺取法+前缀和)

    描述 http://poj.org/problem?id=2566 给出一个整数序列,并给出非负整数t,求数列中连续区间和的绝对值最接近k的区间左右端点以及这个区间和的绝对值. Bound Found ...

  6. [POJ 1151] Atlantis

    一样的题:HDU 1542 Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18148   Accepted ...

  7. [HDU 1561] The more, The Better

    The more, The Better Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. -_-#【JS 优化】把 JS 放到底部

    一开始为以为Javascript脚本尽量放到页面底部加载,是指所有的JS脚本都要放到底部,后来才发现, 并不完全是这样,这里所指的脚本是指那些在加载过程中要执行的脚本,所以一般的处理办法还是页面头部引 ...

  9. 【转】Cannot find -ltinfo when compiling android 4.0.3

    原文网址:http://stackoverflow.com/questions/9055005/cannot-find-ltinfo-when-compiling-android-4-0-3 up v ...

  10. JFinal介绍

    JFinal是基于Java语言的极速Web + ORM框架,其核心设计目标是开发迅速.代码量少.学习简单.功能强大.轻量级.易扩展.Restful.在拥有Java语言所有优势的同时再拥有Ruby.Py ...