Codeforces 1251D Salary Changing
D. Salary Changing
大意: 有n个变量, 每个变量有一个取值区间, 要求给这n个变量赋值, 使得n个变量的和不超过S且中位数尽量大(n一定为奇数)
二分答案, 中位数大于等于mid就是问能不能有(n+1)/2个变量的值大于等于mid, 排序贪心就完事了.
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long i64;
const int maxn = 200002;
struct interval{
int l, r;
bool operator < (const interval &B)const{
return l < B.l;
}
}E[maxn];
bool ok(int target, int n, i64 S){
i64 cost = 0;
int cnt = 0;
for(int i=n;i>=1;--i){
if(cnt*2<n&&E[i].r>=target){
if(E[i].l>=target)cost += E[i].l;
else cost += target;
cnt++;
}else{
cost += E[i].l;
}
}
return cost<=S && cnt*2>n;
}
void work(){
i64 S;
int n;
scanf("%d%lld", &n, &S);
for(int i=1;i<=n;++i){
scanf("%d%d", &E[i].l, &E[i].r);
}
sort(E+1, E+n+1);
int L = E[n/2+1].l;
int R = 1000000000;
while(L<=R){
int mid = (L+R)>>1;
if(ok(mid, n, S))L = mid + 1;
else R = mid - 1;
}
printf("%d\n", L-1);
}
int main(){
int t;scanf("%d", &t);
while(t--){
work();
}
return 0;
}
Codeforces 1251D Salary Changing的更多相关文章
- codeforces 1251D Salary Changing (二分+贪心)
(点击此处查看原题) 题意分析 一共有s元钱,要用这些钱给n个人发工资,发给每个人的工资si有最少和最多限制 si ∈[li,ri],在发给n个人的总工资小于s的情况下,要求发给n个人中的工资的中位数 ...
- codeforces D Salary Changing
题意:给你n个人,和s块钱,每个人都有一个工资区间,你给所有人都发工资.然后要他们工资的中位数最大. 思路:二分找那个值.那个值要满足至少有n/2+1个工资区间内. #include<cstdi ...
- Educational Codeforces Round 75 (Rated for Div. 2) D. Salary Changing
链接: https://codeforces.com/contest/1251/problem/D 题意: You are the head of a large enterprise. n peop ...
- CodeForces 396C On Changing Tree
On Changing Tree Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...
- D. Salary Changing(找中位数)
题:https://codeforces.com/contest/1251/problem/D 题意:给你n个单位需要满足达到的区间,再给个s,s是要分配给n的单位的量,当然∑l<=s,问经过分 ...
- CodeForces - 396C On Changing Tree(树状数组)
题目大意 给定一棵以1为根的树,初始时所有点为0 给出树的方式是从节点2开始给出每一个点的父亲 然后是 $m$ 次操作,分为两种 $1 v,k,x$ 表示在以v为根的子树中的每一个点上添加 $x-i* ...
- CodeForces - 1251D (贪心+二分)
题意 https://vjudge.net/problem/CodeForces-1251D 您是一个大型企业的负责人.在您的企业当中共有n位员工为您工作,而且非常有趣的事是这个n是一个奇数(n不能被 ...
- 二分题 D - Salary Changing codeforce
题意:给出n个人(n是奇数),s钱:s为总的可以付工钱的钱: 每一个工人有一个付工钱的区间,只要在这个区间范围内,随便一个数都可以当作给这个工人付了钱: 老板要付给每个工人钱,并且付钱的中位数要尽可能 ...
- Educational Codeforces Round 75
目录 Contest Info Solutions A. Broken Keyboard B. Binary Palindromes C. Minimize The Integer D. Salary ...
随机推荐
- 如何使用RedisTemplate访问Redis数据结构之Zset
Redis的ZSet数据结构 Redis 有序集合和无序集合一样也是string类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个double类型的分数.redis正是通过分数来为集合 ...
- Spark学习(4) Spark Streaming
什么是Spark Streaming Spark Streaming类似于Apache Storm,用于流式数据的处理 Spark Streaming有高吞吐量和容错能力强等特点.Spark Stre ...
- Django-04-路由系统
1. 概述 URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL模式以及 2. path转换器 在django2.0 以上的版本中,默认使用的是path转换器,我们首先以此 ...
- 【LEETCODE】60、数组分类,适中级别,题目:75、560、105
package y2019.Algorithm.array.medium; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.a ...
- pytest_skip跳过用例
前言 pytest.mark.skip可以标记无法在某些平台上运行的测试功能,或者您希望失败的测试功能 skip意味着只有在满足某些条件时才希望测试通过,否则pytest应该跳过运行测试. 常见示例是 ...
- lsb_release -a linux查看版本未找到命令
解决方案 yum install -y redhat-lsb 安装完后
- CentOS -- 新建用户并使能密钥登录
目录 1. 新建用户 2. 为新用户授权 2.1. 方法一:把新用户添加到wheel用户组中 2.2. 方法二:把新用户添加到sudoers列表中 3. 新用户使能 SSH 密钥登录 4. 其它 4. ...
- onActivityResult方法的使用
转发自:https://blog.csdn.net/hacker_crazy/article/details/78345450 在进行界面间的跳转和传递数据的时候,我们有的时候要获得跳转之后界面传递回 ...
- js动态替换和插入字符串
替换 str是我要查询的内容loot.SERVE.file 是要被替换的内容g 全局替换"" 去替换的内容,我这里是空str.replace(new RegExp(loot.SER ...
- Unity Physicals Rigidbody with multiple colliders
Rigidbody with multiple colliders adding colliders changes the center of mass and rotation behaviour ...