Enumeration median + priority Queue Pre-preprocessing X number of n minimum and
#include <cstdio>#include<cstring>#include<cmath>#include<queue>#include<vector>#include<iostream>#include<algorithm>using namespaceStd;typedefLong LongLL;Const intmaxn=100000+Ten;intN,c; LL F;structx{LL S; LL v;} T[MAXN];p riority_queue<LL>P; LL DP1[MAXN],DP2[MAXN];BOOLcmpConstX&a,Constx&b) { returna.s<B.S;}intMain () {scanf ("%d%d%lld",&n,&c,&f); for(intI=1; i<=c; i++) scanf ("%lld%lld",&t[i].s,&t[i].v); Sort (T+1, t+1+c,cmp); LL ans=-1; if(c>=N) {if(n==1) { for(intI=1; i<=c; i++)if(t[i].v<=f) ans=T[i].s; } Else { while(!q.empty ()) Q.pop (); intNum= (n1)/2; for(intI=1; i<=num; i++) dp1[num]=dp1[num]+T[i].v,q.push (T[I].V); for(inti=num+1; i<=c; i++) { if(T[i].v>=q.top ()) dp1[i]=dp1[i-1]; Else{Dp1[i]=dp1[i-1]-(Q.top ()-t[i].v); Q.pop (); Q.push (T[I].V); } } while(!q.empty ()) Q.pop (); for(intI=c; i>=c-num+1; i--) dp2[c-num+1]=dp2[c-num+1]+T[i].v,q.push (T[I].V); for(intI=c-num; i>=1; i--) { if(T[i].v>=q.top ()) dp2[i]=dp2[i+1]; Else{Dp2[i]=dp2[i+1]-(Q.top ()-t[i].v); Q.pop (); Q.push (T[I].V); } } for(intI=1; i<=c; i++) { if(I-1<num| | C-i<num)Continue; if(dp1[i-1]+dp2[i+1]+T[I].V<=F) ans=T[i].s; }}} printf ("%lld\n", ans); return 0;}
POJ Moo university-financial Aid