# poj2010

</pre><pre name="code" class="html"><img src="https://img-blog.csdn.net/20151117215338104?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /><pre name="code" class="html">#include"iostream"
#include"cstdio"
#include"queue"
#include"algorithm"
using namespace std;
struct Cow{int s,f;}cow[101000];
bool cmp(const Cow &a,const Cow &b)
{
if(a.s!=b.s)
return a.s>b.s;
else
return a.f<b.f;
}
int main()
{
priority_queue<int>Q;
int n,c,f,i,nu,dpl[101000],dpr[101000];
while(scanf("%d%d%d",&n,&c,&f)!=EOF)
{
for(i=1;i<=c;i++)
cin>>cow[i].s>>cow[i].f;
sort(cow+1,cow+1+c,cmp);
nu=n/2;
int sum=0;
while(!Q.empty())
Q.pop();
for(i=1;i<=nu;i++)
Q.push(cow[i].f),sum+=cow[i].f;
dpl[nu]=sum;
for(i=nu+1;i<=c;i++)
{
if(cow[i].f>=Q.top())
dpl[i]=sum;
else
{
sum=sum-Q.top()+cow[i].f;
Q.pop();
Q.push(cow[i].f);
dpl[i]=sum;
}
}
sum=0;
while(!Q.empty())
Q.pop();
for(i=c;i>=c-nu+1;i--)
Q.push(cow[i].f),sum+=cow[i].f;
dpr[c-nu+1]=sum;
for(i=c-nu;i>=1;i--)
{
if(cow[i].f>=Q.top())
dpr[i]=sum;
else
{
sum=sum-Q.top()+cow[i].f;
Q.pop();
Q.push(cow[i].f);
dpr[i]=sum;
}
}
bool flag=false;
for(i=nu+1;i<=c-nu;i++)
{
if(cow[i].f+dpl[i-1]+dpr[i+1]<=f)
{
cout<<cow[i].s<<endl;
flag=true;
break;
}
}
if(!flag)
cout<<"-1"<<endl;
}

}


#### Poj 2010(优先队列)

2013-08-07 12:43:26

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

2015-08-22 23:47:24

#### POJ-2010-优先队列（解题报告）

2014-07-31 21:13:10

#### POJ2010

2017-10-25 19:21:25

#### poj2010 优先队列

2015-08-09 10:07:39

#### poj2010（优先队列）

2017-08-03 16:01:06

#### 优先队列 POJ2010

2015-09-10 09:30:32

#### 优先队列 POJ2010

2018-04-12 23:58:32

#### POJ2010 优先队列

2018-03-07 17:33:12