Codeforces Round #251 (Div. 2) 439D Devu and his Brother(脑洞)
来源:互联网 发布:java gbk utf8 转换 编辑:程序博客网 时间:2024/05/17 07:12
给定a数组和b数组,两数组的元素每次可以增减1,要求增减最少使得a数组中最小数大于等于b数组最大数。
把a,b数组都存到c数组中,c[m]即为最终那个数,然后一个一个加起来就是答案。
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;const int maxn = 1e5 + 5;typedef long long ll;int main(int argc, char const *argv[]){int n, m;while(scanf("%d%d", &n, &m) != EOF) {ll a[maxn], b[maxn], c[maxn * 2];for(int i = 0; i < n; ++i) {scanf("%lld", &a[i]);c[i] = a[i];}for(int j = 0; j < m; ++j) {scanf("%lld", &b[j]);c[j + n] = b[j];}sort(c, c + m + n);ll ans = 0, t = c[m];for(int i = 0; i < n; ++i)ans += max((ll)0, t - a[i]);for(int i = 0; i < m; ++i)ans += max((ll)0, b[i] - t);printf("%lld\n", ans); }return 0;}
1 0
- 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 (Div. 2) 439D Devu and his Brother(脑洞)
- Codeforces Round #251(Div. 2) 439D. Devu and his Brother 枚举
- Codeforces 439D Devu and his Brother
- Codeforces 439D Devu and his Brother
- CodeForces 439D Devu and his Brother
- Codeforces Round #251 Div2D 439D Devu and his Brother 二分查找STL
- 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
- Codeforecs 439D Devu and his Brother 三分
- CF 439D(251D题)Devu and his Brother
- Codeforces Round #251 (Div. 2) 439C Devu and Partitioning of the Array(脑洞)
- 【Android UI设计与开发】第03期:引导界面(三)仿微信引导界面以及动画效果
- poj 2187 Beauty Contest Andrew
- Wpf ImageSource对象与Bitmap对象的互相转换
- 指针算术
- 迭代器Iterator
- Codeforces Round #251 (Div. 2) 439D Devu and his Brother(脑洞)
- HTML/CSS基础
- Linux平台上SQLite数据库教程(二)——C语言API介绍
- POJ 2184Cow Exhibition(01背包变形)
- linux学习笔记1-虚拟机安装 UBUNTU u盘无法识别
- 【more effective c++读书笔记】【第3章】异常(2)
- Android RecyclerView 使用完全解析 体验艺术般的控件
- ORA-00001: unique constraint (...) violated并不一定是数据冲突
- Linux下创建用户命令