program a_1; var answer,s,tot1,tot2:int64; i,j,l,r,mid,k,n,m,t,max:longint; a,b,w,v,d:array[1..300000]of longint; e:array[1..300000]of int64; c:array[1..300000]of boolean; begin answer:=1000000000000000; readln(n,m,s); for i:=1 to n do begin readln(w[i],v[i]); if v[i]>max then max:=v[i]; end; for i:=1 to m do readln(a[i],b[i]); l:=1; r:=max; mid:=(l+r)shr 1; repeat tot2:=0; fillchar(c,sizeof(c),false); fillchar(d,sizeof(d),0); fillchar(e,sizeof(e),0); for i:=1 to n do if w[i]>=mid then c[i]:=true; for i:=1 to n do if c[i] then begin d[i]:=d[i-1]+1;e[i]:=e[i-1]+v[i];end else begin d[i]:=d[i-1];e[i]:=e[i-1];end; for i:=1 to m do tot2:=tot2+(d[b[i]]-d[a[i]-1])*(e[b[i]]-e[a[i]-1]); if abs(tot2-s)<answer then answer:=abs(tot2-s); if tot2<s then begin r:=mid-1; mid:=(l+r)shr 1; end; if tot2>s then begin l:=mid+1; mid:=(l+r)shr 1; end; if tot2=s then begin writeln(0); halt; end; until r<l; writeln(answer); end. /************************************************************** Problem: 2308 User: admin Language: Pascal Result: Wrong Answer ****************************************************************/