KIKIxiaohua @ 2021-06-19 11:22:08
#include<stdio.h>
#include<math.h>
typedef long long ll;
ll n,m,s,r=-1,l,minn=1e13+100;;
ll w[200100],v[200100],sw[200100],sv[200100],li[200100],ri[200100];
int main(){
scanf("%lld%lld%lld",&n,&m,&s);
for(int i=1;i<=n;i++){
scanf("%lld%lld",&w[i],&v[i]);
if(w[i]>r)r=w[i];
}
for(int i=1;i<=m;i++)scanf("%lld%lld",&li[i],&ri[i]);
while(l<=r){
ll ans=0,mid=(l+r)/2,s1;
for(int i=1;i<=n;i++){
if(w[i]>mid)sw[i]=sw[i-1]+1,sv[i]=sv[i-1]+v[i];
else sw[i]=sw[i-1],sv[i]=sv[i-1];
}
for(int i=1;i<=m;i++){
ans+=(sw[ri[i]]-sw[li[i]-1])*(sv[ri[i]]-sv[li[i]-1]);
}
s1=s-ans;
if(s1>0)r=mid-1;
else l=mid+1;
s1=abs(s1);
if(minn>s1)minn=s1;
}
printf("%lld\n",minn);
return 0;
}
by chenyilei @ 2021-06-19 16:06:34
貌似c的abs不能longlong 用fabs(s1) c 可以过