链接:

https://codeforces.com/contest/1251/problem/D

题意:

You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2).

You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from li to ri dollars. You have to distribute salaries in such a way that the median salary is maximum possible.

To find the median of a sequence of odd length, you have to sort it and take the element in the middle position after sorting. For example:

the median of the sequence [5,1,10,17,6] is 6,

the median of the sequence [1,2,1] is 1.

It is guaranteed that you have enough money to pay the minimum salary, i.e l1+l2+⋯+ln≤s.

Note that you don't have to spend all your s dollars on salaries.

You have to answer t test cases.

思路:

二分, 判断赛的时候贪心判断。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; const int MAXN = 2e5+10; struct Node
{
int l, r;
bool operator < (const Node& rhs) const
{
if (this->l != rhs.l)
return this->l > rhs.l;
return this->r > rhs.r;
}
}node[MAXN];
int n;
LL s; bool Check(LL val)
{
int p = n/2+1;
LL sum = 0;
for (int i = 1;i <= n;i++)
{
if (node[i].r >= val && p > 0)
{
sum += max(val, (LL)node[i].l);
p--;
}
else
{
sum += node[i].l;
}
}
return (sum <= s && p == 0);
} int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
cin >> n >> s;
for (int i = 1;i <= n;i++)
cin >> node[i].l >> node[i].r;
sort(node+1, node+1+n);
LL l = 1, r = s;
LL res = 0;
while(l <= r)
{
LL mid = (l+r)/2;
//cout << mid << endl;
if (Check(mid))
{
res = max(res, mid);
l = mid+1;
}
else
r = mid-1;
}
cout << res << endl;
} return 0;
}

Educational Codeforces Round 75 (Rated for Div. 2) D. Salary Changing的更多相关文章

  1. Educational Codeforces Round 75 (Rated for Div. 2)

    知识普及: Educational使用拓展ACM赛制,没有现场hack,比赛后有12h的全网hack时间. rank按通过题数排名,若通过题数相等则按罚时排名. (罚时计算方式:第一次通过每题的时间之 ...

  2. Educational Codeforces Round 75 (Rated for Div. 2) C. Minimize The Integer

    链接: https://codeforces.com/contest/1251/problem/C 题意: You are given a huge integer a consisting of n ...

  3. Educational Codeforces Round 75 (Rated for Div. 2) B. Binary Palindromes

    链接: https://codeforces.com/contest/1251/problem/B 题意: A palindrome is a string t which reads the sam ...

  4. Educational Codeforces Round 75 (Rated for Div. 2) A. Broken Keyboard

    链接: https://codeforces.com/contest/1251/problem/A 题意: Recently Polycarp noticed that some of the but ...

  5. Educational Codeforces Round 75 (Rated for Div. 2)D(二分)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;pair<int,int>a[20 ...

  6. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  8. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  9. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

随机推荐

  1. mdk编译时的内存分析

    内存四区(代码区,全局区,栈区,堆区) Code:即代码域,它指的是编译器生成的机器指令,这些内容被存储到ROM区. RO-data:Read Only data,即只读数据域,它指程序中用到的只读数 ...

  2. linux根文件系统的挂载过程详解

    一:前言 前段时间在编译kernel的时候发现rootfs挂载不上.相同的root选项设置旧版的image却可以.为了彻底解决这个问题.研究了一下rootfs的挂载过程.特总结如下,希望能给这部份知识 ...

  3. slot 组件的内部传值 v-slot 的使用

    嵌套组件传值 person.vue <template> <div class="vslot-test"> <ul> <li v-for= ...

  4. javascript之new操作符

    new 运算符做了哪些事情 1.新生成了一个对象 2.链接到原型 3.绑定 this 4.返回新对象 自己实现一个 new function create() { // 创建一个空的对象 let ob ...

  5. bootstrap栅格系统的container和row一些关系

    container有个15px的padding,而我们设定的每个col也都有15px的padding,如果两者直接配合,那么就会产生30px的间距,导致内容和浏览器边框的距离较大,所以用row将所有的 ...

  6. Spring Cloud Alibaba学习笔记(2) - Nacos服务发现

    1.什么是Nacos Nacos的官网对这一问题进行了详细的介绍,通俗的来说: Nacos是一个服务发现组件,同时也是一个配置服务器,它解决了两个问题: 1.服务A如何发现服务B 2.管理微服务的配置 ...

  7. 判断上传文件是否为excel

    1. 可以在input上传组件上添加属性accept,这样上传文件的时候,就只能选择excel文件了. <input type="file" accept="app ...

  8. jquery sortable的拖动方法示例详解

    转自:https://hb-keepmoving.iteye.com/blog/1154618 所有的事件回调函数都有两个参数:event和ui,浏览器自有event对象,和经过封装的ui对象   u ...

  9. S5PV210 timer

    TCFG0, R/W, Address = 0xE250_0000 Timer Input Clock Frequency = PCLK / ( {prescaler value + 1} ) / { ...

  10. IntelliJ IDEA.2017.3.4(win7 64位)的安装使用

    下载 1.Idea与Webstorm同为JetBrains公司的产品,因此安装使用方式也极为相似,首先我们打开IDEA的官方下载网站:https://www.jetbrains.com/idea/,点 ...