-----------------------------------------------------------------------------------------------------------------
#include<cstdio>
#include<cstring>
#define MAXN 200005
#define INF 1ll<<60
typedef long long ll;
ll max(ll a,ll b) { return (a>b)?a:b; }
ll min(ll a,ll b) { return (a<b)?a:b; }
ll abs(ll a) { return (a<0)?-a:a; }
ll n,m,w[MAXN],v[MAXN],l[MAXN],r[MAXN],maxw,nl,nr;
ll s,ans=INF,s1[MAXN],s2[MAXN];
void init()
{
scanf("%lld %lld %lld",&n,&m,&s);
for (int i=1;i<=n;i++) { scanf("%lld %lld",&w[i],&v[i]); maxw=max(maxw,w[i]); }
for (int i=1;i<=m;i++) scanf("%lld %lld",&l[i],&r[i]);
}
ll calc(int now)
{
memset(s1,0,sizeof(s1)); memset(s2,0,sizeof(s2));
ll ret=0;
for (int i=1;i<=n;i++) if (w[i]>=now) { s1[i]=s1[i-1]+1; s2[i]=s2[i-1]+v[i]; } else { s1[i]=s1[i-1]; s2[i]=s2[i-1]; }
for (int i=1;i<=m;i++) ret+=(s1[r[i]]-s1[l[i]-1])*(s2[r[i]]-s2[l[i]-1]);
return ret;
}
int main()
{
init();
nl=1,nr=maxw;
while (nl<=nr)
{
int mid=(nl+nr)/2;
ll ret=calc(mid);
if (ret-s《0) { nr=mid-1; ans=min(ans,s-ret); }
else { nl=mid+1; ans=min(ans,ret-s); }
}
printf("%lld",ans);
return 0;
}
---------------------------------------------------------------------------------------------------