sandwich @ 2020-07-31 20:01:10
RT,求助大佬,谢谢大佬们
#include<bits/stdc++.h>
using namespace std;
#define N 2000005
long long n,m,i,j,k,s,w[N],v[N];
long long l[N],r[N],a[N],b[N];
long long g(long long m)
{
long long y=0;
for(int i=1;i<=n;i++)
{
if(w[i]>=m)
{
a[i]=a[i-1]+1;
b[i]=b[i-1]+v[i];
}
else
{
a[i]=a[i-1];
b[i]=b[i-1];
}
}
for(int i=1;i<=m;i++)
y+=(b[r[i]]-b[l[i]-1])*(a[r[i]]-a[l[i]-1]);
return y;
}
int main()
{
long long maxn=0;
cin>>n>>m>>s;
for(i=1;i<=n;i++)
{
scanf("%lld%lld",&w[i],&v[i]);;
maxn=max(maxn,w[i]);
}
for(i=1;i<=m;i++)
scanf("%lld%lld",&l[i],&r[i]);
long long m;
int l=-100,r=maxn+100;
long long ans=9223372036854775807;
int f;
while(l<=r)
{
f=(l+r)/2;
if(g(f)>=s) l=f+1;
else r=f-1;
ans=min(abs(g(l)-s),abs(s-g(r)));
}
cout<<ans;
return 0;
}