Educational Codeforces Round 75 (Rated for Div. 2)D(二分)
#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(二分)的更多相关文章
- Educational Codeforces Round 75 (Rated for Div. 2)
知识普及: Educational使用拓展ACM赛制,没有现场hack,比赛后有12h的全网hack时间. rank按通过题数排名,若通过题数相等则按罚时排名. (罚时计算方式:第一次通过每题的时间之 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
随机推荐
- 三、ZigBee无线网络工具
CC2530概述 CC2530是德州仪器Ti公司用于2.4-GHz IEEE 802.15.4.ZigBee 和 RF4CE 应用的一个真正的片上系统(SoC)解决方案,是作为ZigBee无线传 感网 ...
- TWF
design seq1_b3 sta_label 0.0-1.0 0.0-1.0 1e-9 # clocks# clockID clock_name period rise_edge fall_edg ...
- CentOS 7升级gcc版本
Centos 7默认gcc版本为4.8,有时需要更高版本的,这里以升级至8.3.1版本为例,分别执行下面三条命令即可,无需手动下载源码编译 1.安装centos-release-scl sudo yu ...
- CSS布局的四种定位方式
1.static(静态定位): 默认值.没有定位,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明).参考上篇随笔. 2.relative(相对 ...
- cmd命令和快捷键
命令 含义 盘名: 从C盘到其他盘时输入 dir 查看当前文件夹下的内容 cd 目录名称 选择目录 cd.. 退回当前目录的上一级目录 cd\ 回到根目录 md 目录名称 创建目录 rd 目录名称 删 ...
- 数位dp(Balanced Numbers )
题意:一个数,如果满足奇数的数字出现偶数次,偶数的数字出现奇数次, 就是符合的数,注比如:12313 就满足,因为1 3出现了偶数次.2出现了奇数次 思路,对于这道题,就是状态压缩加dp: 对于一个 ...
- 拓扑排序 判断给定图是否存在合法拓扑序列 自家oj1393
//拓扑排序判断是否有环 #include<cstdio> #include<algorithm> #include<string.h> #include<m ...
- Uncaught TypeError: Cannot read property 'addEventListener' of null
<script type="text/javascript"> var body1=document.getElementById('#body') </scri ...
- php:对象(object)数据类型实例详解
什么是对象? 对象是存储数据和有关如何处理数据的信息的数据类型.是系统中用来描述客观事物的一个实体,它是构成系统的一个基本单位.一个对象由一组属性和对这组属性进行操作的一组服务组成. 语法 在 PHP ...
- MySQL学习(七) 索引选择(半原创)
概述 该篇文章主要阐述一个例子(例子来自参考资料,侵删),然后总结今天相关的知识点. 例子 (例子来自参考文章,非原创) 创建表并插入数据,并执行查询 CREATE TABLE `t` ( `id` ...