xps0606 @ 2021-05-31 13:20:25
#include<bits/stdc++.h>
#define ll long long
#define N 200000
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return f*x;
}
ll n=read(),m=read(),s=read(),w[N],v[N],l[N],r[N],s1[N],sum[N],ans=10e18,maxn=0;
bool check(ll x){
memset(sum,0,sizeof(sum));
memset(s1,0,sizeof(s1));
ll y=0;
for(int i=1;i<=n;i++){
s1[i]=s1[i-1];
sum[i]=sum[i-1];
if(w[i]>=x) {
sum[i]++;
s1[i]+=v[i];
}
}
for(int i=1;i<=m;i++) y+=(sum[r[i]]-sum[l[i]-1])*(s1[r[i]]-s1[l[i]-1]);
maxn=(ll)abs(s-y);
if(y>s) return true;
return false;
}
int main(){
for(int i=1;i<=n;i++) w[i]=read(),v[i]=read();
for(int i=1;i<=m;i++) l[i]=read(),r[i]=read();
ll x=0,y=10e18;
while(x<=y)
{
ll mid=x+y>>1;
if(check(mid)) x=mid+1;
else y=mid-1;
if(maxn<ans) ans=maxn;
}
printf("%lld",ans);
return 0;
}
by 阿丑 @ 2021-05-31 13:33:41
@xps0606 数组应该开大点
by xps0606 @ 2021-05-31 13:38:31
谢谢,已A。