#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
pair<int,int>a[200007];
int n;
long long s;
bool check(int x){
int num=0;
long long sum=s;
for(int i=n;i;--i){
if(a[i].first>=x)
++num;
else if(a[i].second>=x&&sum>=x-a[i].first){
++num;
sum-=x-a[i].first;
}
}
if(num>=n/2+1)
return 1;
return 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--){
cin>>n>>s;
int x,y;
for(int i=1;i<=n;++i){
cin>>x>>y;
a[i]={x,y};
s-=x;
}
sort(a+1,a+1+n);
int l=a[n/2+1].first,r=1e9;
int ans=0;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)){
ans=mid;
l=mid+1;
}
else
r=mid-1;
}
cout<<ans<<"\n";
}
return 0;
}

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

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

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

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  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. 在多租户(容器)数据库中如何创建PDB:方法4 克隆远程Non-CDB

    基于版本:19c (12.2.0.3) AskScuti 创建方法:克隆远程Non-CDB(从 Non-CDB 中进行远程克隆).将 非CDB数据库PROD1 远程克隆为 CDB1 中的 PDB7 对 ...

  2. python3练习100题——023

    再做一道,把这周的任务搞定- 其实看到这道题,很熟悉,让我想起大一时被C语言支配的恐惧.那个时候不停的在push自己,给自己很大的压力.上C语言课的时候让人昏昏欲睡,但是还是逼迫自己打起精神来学习,一 ...

  3. springboot中集成memcached

    前言 Memcached 是一个高性能的分布式内存对象缓存系统,其存储性能在某些方面不比redis差,甚至在文本类型数据的存储上性能略优于redis,本文将介绍如何在springboot中集成memc ...

  4. 20191225_Python构造函数知识以及相关注意事项

    Python构造函数格式为__init__() 注:下划线为两个而不是一个 可以有无参构造 instance: class city: def printout(self,first,second): ...

  5. 【资源分享】Gmod动态方框透视脚本

    *----------------------------------------------[下载区]----------------------------------------------* ...

  6. 转载:Laplace 变换

    转自: https://www.zhihu.com/question/22085329 https://wenku.baidu.com/view/691d4629640e52ea551810a6f52 ...

  7. Vue-cli3 项目配置 Vue.config.js( 代替vue-cli2 build config)

    Vue-cli3 搭建的项目 界面相对之前较为简洁 之前的build和config文件夹不见了,那么应该如何配置 如webpack等的配那 只需要在项目的根目录下新建 vue.config.js 文件 ...

  8. python 序列 倒着取元素

    当要倒着取元素时,用s[-2]只能取一个, 如果取多个时用s[-9:-1],注意,最后一个-1是不取出来的. 此时要用s[-9:] 最后一个空着就可以取出来了.

  9. 如和针对CPU时间百分比,Mem使用bytes,以及Network RecvBytes/SendBytes指标性能压测数据可视化

    设计思路:通过jmeter5.1压测获取cpu,Mem,Network的压测指标数据利用pandas+openpyxl进行数据可视化: 涉及添加jar包:下载地址:https://files.cnbl ...

  10. MyBatis(5)——解决属性名与列名不一致的问题

    解决属性名与列名不一致的问题 问题描述: 当实体类的属性与数据库的列名不对应时取不到该列数据 说明:MyBatis会根据查询的列名设值(列名的setter方法),然后以此列名为做查询等操作,在此过程中 ...