Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
双重快排可以实现贴PASCAL代码》》》》》type arr=array[0..100000]of longint; var a,b,c,d:arr; n,m,t,i,l,r,King,Exo,mid,x,y,k:longint; procedure qsort(var a,b:arr); procedure sort(l,r:longint); var i,j,x,y:longint; begin i:=l; j:=r; x:=a[(l+r)>>1]; repeat while a[i]<x do inc(i); while x<a[j] do dec(j); if not(i>j) then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; y:=b[i]; b[i]:=b[j]; b[j]:=y; inc(i); dec(j); end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; begin sort(1,m); end; begin read(n,m,t); for i:=1 to m do read(a[i],b[i]); c:=a; d:=b; qsort(b,a); qsort(c,d); for i:=1 to n do inc(Exo,b[i]); if Exo>t then begin writeln(-1); halt; end; l:=1; r:=m; while l<r do begin mid:=(l+r+1)>>1; King:=c[mid]; Exo:=d[mid]; x:=0; y:=0; i:=0; k:=0; while (x+y<n-1)and(i<m) do begin inc(i); if (k=0)and(a[i]=King)and(b[i]=d[mid]) then begin inc(k); continue; end; if (x<n>>1)and(a[i]<King) then begin inc(x); inc(Exo,b[i]); end; if a[i]>=King then begin inc(y); inc(Exo,b[i]); end; end; if (Exo>t)or(x+y<n-1) then r:=mid-1 else l:=mid; end; writeln(c[l]); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator