Robin Hood
Robin Hood
题意
给你n个人和他们的钱数,然后给你k天,每天可以从最高钱数的人那边取一块钱给最少钱数的人,问最后钱数最多的人和钱数最少的人相差多少;
思路
二分最钱数,能下降到的位置\(low\),和最低钱数能够上涨到的位置\(high\),如果\(low > high\),那么答案就是\(low-high\),
如果\(low <= high\)那么经过k天后如果所有的钱数和能够整除n则答案为0,否则相差1
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL node[600000];
LL n,k;
bool checklo(LL mid)
{
LL sum = 0;
for(int i = 0; i < n; i++)
if(node[i] > mid)
sum += node[i] - mid;
return sum <= k;
}
bool checkhi(LL mid)
{
LL sum = 0;
for(int i = 0; i < n; i++)
if(node[i] < mid)
sum += mid - node[i];
return sum <= k;
}
int main(void)
{
scanf("%lld %lld",&n,&k);
LL sum = 0;
for(int i = 0; i < n; i++)
{
scanf("%lld",&node[i]);
sum += node[i];
}
LL l = 0,r = 1e9;
LL loid = -1;
while(l <= r)
{
LL mid = (l+r)/2;
if(checklo(mid))
loid = mid,r = mid - 1;
else l = mid + 1;
}
l = 0,r = 1e9;
LL hiid = -1;
while(l <= r)
{
LL mid = (l+r)/2;
if(checkhi(mid))
hiid = mid,l = mid + 1;
else r = mid - 1;
}
if(hiid < loid)
printf("%lld\n",loid - hiid);
else
{
if(sum%n)
printf("1\n");
else printf("0\n");
}
return 0;
}
Robin Hood的更多相关文章
- Codeforces Round #352 (Div. 2) D. Robin Hood 二分
D. Robin Hood We all know the impressive story of Robin Hood. Robin Hood uses his archery skills a ...
- Curious Robin Hood(树状数组+线段树)
1112 - Curious Robin Hood PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 64 ...
- CF 672D Robin Hood(二分答案)
D. Robin Hood time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #352 (Div. 1) B. Robin Hood 二分
B. Robin Hood 题目连接: http://www.codeforces.com/contest/671/problem/B Description We all know the impr ...
- 【CodeForces】671 B. Robin Hood
[题目]B. Robin Hood [题意]给定n个数字的序列和k次操作,每次将序列中最大的数-1,然后将序列中最小的数+1,求最终序列极差.n<=5*10^5,0<=k<=10^9 ...
- Codeforces 671B/Round #352(div.2) D.Robin Hood 二分
D. Robin Hood We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and ...
- Codeforces Round #352 (Div. 1) B. Robin Hood (二分)
B. Robin Hood time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces 672D Robin Hood(二分好题)
D. Robin Hood time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- cf671B Robin Hood
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to s ...
- Codeforces Round #352 (Div. 1) B. Robin Hood
B. Robin Hood 讲道理:这种题我是绝对不去(敢)碰的.比赛时被这个题坑了一把,对于我这种不A不罢休的人来说就算看题解也要得到一个Accepted. 这题网上有很多题解,我自己是很难做出来的 ...
随机推荐
- urllib的基本使用介绍
1. urllib中urlopen的基本使用介绍 1 ### urllib中urlopen的基本使用介绍 2 3 ## urlopen的基本用法(GET请求) 4 import urllib.requ ...
- admire, admit
admire 当别人admire你时,小心掉进泥潭(mire).词源:to wonder. wonderful夸人,awful骂人,awesome夸人.admiral与admire词源不同,碰巧长得像 ...
- day04 Linux基础命令
day04 Linux基础命令 查看帮助信息命令 1.man命令:man命令的功能是查看指定命令的详细解释. 格式:man [具体需要被查看的命令] [root@localhost ~]# man r ...
- Spark(八)【利用广播小表实现join避免Shuffle】
目录 使用场景 核心思路 代码演示 正常join 正常left join 广播:join 广播:left join 不适用场景 使用场景 大表join小表 只能广播小表 普通的join是会走shuff ...
- Shell学习(四)——shell中各种括号的作用
参考博客: [1]shell中各种括号的作用().(()).[].[[]].{} [2]shell中的单层大/中/小括号.双层大中小括号.命令替换等 一.前言 目录 单括号() 双括号(( )) 单中 ...
- 优化if else嵌套代码
写在前面 不知大家有没遇到过像"横放着的金字塔"一样的if else嵌套: if (true) { if (true) { if (true) { if (true) { if ( ...
- DP-Burst Balloons
leetcode312: https://leetcode.com/problems/burst-balloons/#/description Given n balloons, indexed fr ...
- linux 挂载本地iso
mount -t iso9660 -o loop /mnt/temp/rhel-server-6.5-i386-dvd.iso /mnt/cdrom -t :设备类型 iso9660是指CD-ROM光 ...
- Bitmaps与优化
1.有效的处理较大的位图 图像有各种不同的形状和大小.在许多情况下,它们往往比一个典型应用程序的用户界面(UI)所需要的资源更大. 读取一个位图的尺寸和类型: 为了从多种资源来创建一个位图,Bitma ...
- html href页面跳转获取参数
//传递参数 var id = columnData.id; var companyname = encodeURI(columnData.companyname); var linename = e ...