#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. 嵌入式Linux学习---进程(1)

    什么是一个进程?当用户敲入命令执行一个程序的时候,对系统而言,它将启动一个进程.但和程序不同的是,在这个进程中,系统可能需要再启动一个或多个进程来完成独立的多个任务.多进程编程的主要内容包括进程控制和 ...

  2. Runtime.getRuntime.exec()执行linux脚本导致程序卡死有关问题

    Runtime.getRuntime.exec()执行linux脚本导致程序卡死问题问题: 在Java程序中,通过Runtime.getRuntime().exec()执行一个Linux脚本导致程序被 ...

  3. vue插槽(slot)的模板与JSX写法

    vue官网API: 插槽:https://cn.vuejs.org/v2/guide/components-slots.html JSX:https://cn.vuejs.org/v2/guide/r ...

  4. 基于Docker的Mysql Cluster集群

    参考 mysql-cluster镜像 https://medium.com/@ahmedamedy/mysql-clustering-with-docker-611dc28b8db7 使用Docker ...

  5. 【译】PHP 内核 — 字符串管理

    [译]PHP 内核 - 字符串管理 (Strings management: zend_string 译文) 原文地址:http://www.phpinternalsbook.com/php7/int ...

  6. IDEAVIM 常用快捷键总结和使用说明

    ---title: ideavim常用快捷键总结和使用tags: grammar_cjkRuby: true--- #### `待办` ideavim用于编程的常用快捷键说明 常用快捷键 插入(光标前 ...

  7. MODULE BUILD FAILED: ERROR: COULDN’T FIND PRESET “ES2015” RELATIVE TO DIRECTORY

    npm run dev 遇到报错: Module build failed: Error: Couldn't find preset "es2015" relative to di ...

  8. Anaconda的安装及tensorflow和各个库的安装

    首先,在anaconda官网https://www.anaconda.com/download/下载想要的版本,2.7或者3+,建议用3.0以上的版本,因为相对来说,功能更加的多样. 下载完成后将安装 ...

  9. CLR处理损坏状态的异常

    你有没有写过不太正确但足够接近的代码?当一切顺利的时候,你是否不得不编写运行良好的代码,但是你不太确定当出了问题时会发生什么?有一个简单的.不正确的语句可能位于您编写或必须维护的代码中:catch ( ...

  10. nfs 动态文件挂载读写权限设置

    nfs 动态文件挂载读写权限设置 待办 ll 命令查看文件夹权限 参考设置共享文件夹https://www.linuxidc.com/Linux/2018-11/155331.htm