CodeForces 439D Devu and his Brother
来源:互联网 发布:药品物流配送软件 编辑:程序博客网 时间:2024/05/17 05:07
/*题目链接:http://codeforces.com/contest/439/problem/D题意大概 给两个数组 分别有n,m个数 要使第一个数组的最小值 不小于 第二个数组的最大值,你所能做的就是对数组中的某一个数进行+1/-1的操作。最后问操作次数最少需要多少次。把两个数组里的数存到同一个数组里,然后升序排序,这样我们就得到了一条线性的数列,那么既然是n+m个数里前m个要比后n个小,也就很自然的能找到平衡点为数列当中的第m个数了。想反驳但是又没理。。。。 */#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <vector>#include <cmath>#include <stack>#include <string>#include <sstream>#include <map>#include <set>#define pi acos(-1.0)#define LL long long#define ULL unsigned long long#define inf 0x3f3f3f3f#define INF 1e18#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1#define debug(a) printf("---%d---\n", a)#define mem0(a) memset(a, 0, sizeof(a))#define memi(a) memset(a, inf, sizeof(a))#define mem1(a) memset(a, -1, sizeof(a))#define input1(a) scanf("%d", &a)#define input2(a,b) scanf("%d %d", &a, &b)#define input3(a,b,c) scanf("%d %d %d", &a, &b, &c)using namespace std;typedef pair<int, int> P;const double eps = 1e-10;const int maxn = 1e5 + 5;const int N = 1e4 + 5;const int mod = 1e8;int a[maxn], b[maxn], c[2*maxn];LL max(LL a, LL b){if (a > b) return a;return b;}int main(void){//freopen("in.txt","r", stdin);int n, m;cin >> n >> m;for (int i = 1; i <= n; i++){cin >> a[i];c[i] = a[i];}for (int i = 1; i <= m; i++){cin >> b[i];c[i+n] = b[i];}sort(c+1, c+1+m+n);LL tmp = c[m], ans = 0;for (int i = 1; i <= n; i++)ans += max(0, tmp-a[i]);for (int i = 1; i <= m; i++)ans += max(0, b[i]-tmp);cout << ans << endl; return 0;}
0 0
- Codeforces 439D Devu and his Brother
- Codeforces 439D Devu and his Brother
- CodeForces 439D Devu and his Brother
- Codeforces 439D Devu and his Brother 三分
- Codeforces 439D Devu and his Brother(排序)
- Codeforces 439D Devu and his Brother【思维+三分查找】
- 439 D. Devu and his Brother
- CF 439D Devu and his Brother
- Codeforces Round #251 (Div. 2) D. Devu and his Brother
- Codeforces Round#251(Div 2)D Devu and his Brother
- Codeforces Round #251 (Div. 2) D Devu and his Brother
- Codeforces Round #251 (Div. 2)-D. Devu and his Brother
- Codeforces Round #251 Div2D 439D Devu and his Brother 二分查找STL
- Codeforces Round #251 (Div. 2) 439D Devu and his Brother(脑洞)
- Codeforces Round #251(Div. 2) 439D. Devu and his Brother 枚举
- Codeforecs 439D Devu and his Brother 三分
- CF 439D(251D题)Devu and his Brother
- codeforces 66D D. Petya and His Friends( 数论+构造)
- 【J2SE】IO初步
- gulp入门
- 判断第二个日期比第一个日期大
- Missing number in matrix
- Jedis连接Redis
- CodeForces 439D Devu and his Brother
- Tomcat的优化经验
- 网络复习日志1
- CCF 2016 4-1 折点计数
- 数据结构与算法分析笔记与总结(java实现)--链表问题面试笔试注意点
- 移动App测试一些崩溃原因及触发崩溃的场景
- HTTP请求的GET与POST方式的区别
- Android调用startForeground 但不显示通知
- Docker启动一个Centos镜像