pichangqian @ 2022-02-17 22:24:43
#include<stdio.h>
int main()
{
int n,m,i;
long long s;
scanf("%d%d%lld",&n,&m,&s);
int a[n][2],b[m][2],max=1,min=0xfffffff;
for(i=0;i<n;i++)
{
scanf("%d%d",a[i],a[i]+1);
if(max<a[i][0]) max=a[i][0];
if(min>a[i][0]) min=a[i][0];
}
for(i=0;i<m;i++) scanf("%d%d",b[i],b[i]+1);
int r=max+2,l=min-1,mid;
long long sum,ans=0xFFFFFFFFFFFFFFF;
while(r>=l)
{
mid=(r+l)/2,sum=0;
int pre_n[n+1],pre_v[n+1];
pre_n[0]=pre_v[0]=0;
for(i=1;i<=n;i++)
{
if(a[i-1][0]>=mid) pre_n[i]=pre_n[i-1]+1,pre_v[i]=pre_v[i-1]+a[i-1][1];
else pre_n[i]=pre_n[i-1],pre_v[i]=pre_v[i-1];
}
for(i=0;i<m;i++) sum+=(pre_n[b[i][1]]-pre_n[b[i][0]-1])*(pre_v[b[i][1]]-pre_v[b[i][0]-1]);
long long ans_x=sum>s?sum-s:s-sum;
if(ans_x<ans) ans=ans_x;
if(ans_x=0) break;
else if(sum<s) r=mid-1;
else if(sum>s) l=mid+1;
}
printf("%lld",ans);
return 0;
}
by pichangqian @ 2022-02-21 09:18:27
不用看了,我找出错误了