#include<iostream> #include<cstdlib> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iomanip> #include<ctime> #include<queue> #include<stack> #define rg register #define lst long long #define N 200050 #define Inf 2147483647 using namespace std; int n,m,mx=-1,mn=Inf; lst res,s,ss; lst ans=999999999999999999; int w[N],v[N],l[N],r[N]; lst tot[N],num[N]; inline lst read() { rg lst s=0,m=1;rg char ch=getchar(); while(ch!=‘-‘&&(ch<‘0‘||ch>‘9‘))ch=getchar(); if(ch==‘-‘)m=-1,ch=getchar(); while(ch>=‘0‘&&ch<=‘9‘)s=(s<<3)+(s<<1)+ch-‘0‘,ch=getchar(); return s*m; } inline lst a_b_s(rg lst t){return t>=0?t:-t;} inline bool check(rg int lim) { res=0,ss=0; memset(tot,0,sizeof(tot)); memset(num,0,sizeof(num)); for(rg int i=1;i<=n;++i) { num[i]=num[i-1],tot[i]=tot[i-1]; if(w[i]>=lim)num[i]++,tot[i]+=v[i]; } for(rg int i=1;i<=m;++i) ss+=(num[r[i]]-num[l[i]-1])*(tot[r[i]]-tot[l[i]-1]); res=a_b_s(ss-s); if(ss>s)return 1; else return 0; } int main() { n=read(),m=read(),s=read(); for(rg int i=1;i<=n;++i) { w[i]=read(),v[i]=read(); mx=max(mx,w[i]),mn=min(mn,w[i]); } for(rg int i=1;i<=m;++i) l[i]=read(),r[i]=read(); rg int le=mn-1,ri=mx+2; while(le<=ri) { rg int mid=(le+ri)>>1; if(check(mid))le=mid+1; else ri=mid-1; ans=min(ans,res); } cout<<ans<<endl; return 0; }