# poj2010 Moo University - Financial Aid 二分

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,s;
struct Z{
int x;
int y;
int z;
}z1[100005],z2[100005];
bool cmp(Z& a,Z& b){
return a.x<b.x;
}
bool cmp1(Z& a,Z& b){
return a.y<b.y;
}
int main(){
cin>>m>>n>>s;
int ans=-1;
for(int i=0;i<n;i++){
scanf("%d%d",&z1[i].x,&z1[i].y);
}
sort(z1,z1+n,cmp);
for(int i=0;i<n;i++){
z1[i].z=z2[i].z=i;
z2[i].x=z1[i].x;
z2[i].y=z1[i].y;
}
memcpy(z2, z1, sizeof(Z) * n);
sort(z2,z2+n,cmp1);
int l=0,r=n;
while(r-l>1){
int mid=(l+r)/2;
int sum=z1[mid].y;
int left=0,right=0;
for(int i=0;i<n;++i){
if((z2[i].z<mid)&&(sum+z2[i].y<=s)&&(left<m/2)){
left++;
sum+=z2[i].y;
}
else if((z2[i].z>mid)&&(z2[i].y+sum<=s)&&(right<m/2)){
sum+=z2[i].y;
right++;
}
}
if((left<m/2)&&(right<m/2)){
ans=-1;
break;
}
else if(left<m/2)
l=mid;
else if(right<m/2)
r=mid;
else {
ans=z1[mid].x;
l=mid;
}
}
cout<<ans<<endl;
}

#### POJ2010--Moo University-Financial Aid（二分）

2015-08-22 23:47:24

#### poj2010 二分做法

2016-06-12 20:55:25

#### POJ3104_Drying_二分

2017-02-23 21:39:54

#### 二分——POJ3388

2014-12-11 13:15:17

#### POJ 3104 Drying （二分）

2017-03-09 14:11:06

#### Moo University - Financial Aid (poj 2010 优先队列 或者 二分)

2015-03-21 15:42:53

#### Moo University - Financial Aid(2010)

2014-10-30 20:07:03

#### poj2010 Moo University - Financial Aid

2016-03-16 12:58:01

#### poj2010 Moo University - Financial Aid

2014-09-18 10:52:39

#### POJ2010 Moo University - Financial Aid

2014-05-20 18:57:48