思路:
二分;
代码:
#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
#define ll long long
#define INF 0x7fffffff
ll n,m,sum[maxn],wi[maxn],vi[maxn],s;
ll li[maxn],ri[maxn],sumn[maxn],flag;
inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'')Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
int solve(ll val)
{
sum[]=,sumn[]=;
for(ll i=;i<=n;i++)
{
sum[i]=sum[i-],sumn[i]=sumn[i-];
if(wi[i]>=val) sum[i]+=vi[i],sumn[i]++;
}
ll res=;
for(ll i=;i<=m;i++) res+=(sumn[ri[i]]-sumn[li[i]-])*(sum[ri[i]]-sum[li[i]-]);
if(res>=s)
{
flag=res-s;
return false;
}
else
{
flag=s-res;
return true;
}
}
int main()
{
in(n),in(m),in(s);
for(ll i=;i<=n;i++) in(wi[i]),in(vi[i]);
for(ll i=;i<=m;i++) in(li[i]),in(ri[i]);
ll l=,r=,ans,mid;
while(l<=r)
{
mid=l+r>>;
if(solve(mid)) ans=mid,r=mid-;
else l=mid+;
}
solve(ans);ll ansl=flag;
solve(ans-);ll ansr=flag;
printf("%lld",min(ansl,ansr));
return ;
}