以P1314为例
#include <bits/stdc++.h>
using namespace std;
const long long a=1e8;
int main(){
freopen("P1314.in","w",stdout);
srand(time(0));
int n=rand()%100+1,m=rand()%100+1;
long long s=(long long)rand()*rand()%a+1;
printf("%d %d %lld\n",n,m,s);
for(int i=1;i<=n;i++){
int w=(long long)rand()*rand()%10000+1;
int v=(long long)rand()*rand()%10000+1;
printf("%d %d\n",w,v);
}
for(int i=1;i<=m;i++){
int l=rand()%n+1;
int r=rand()%n+1;
if(l>r) swap(l,r);
printf("%d %d\n",l,r);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const long long a=1e8;
int main(){
freopen("P1314.in","w",stdout);
srand(time(0));
int n=rand()%100+1,m=rand()%100+1;
long long s=(long long)rand()*rand()%a+1;
printf("%d %d %lld\n",n,m,s);
for(int i=1;i<=n;i++){
int w=(long long)rand()*rand()%10000+1;
int v=(long long)rand()*rand()%10000+1;
printf("%d %d\n",w,v);
}
for(int i=1;i<=m;i++){
int l=rand()%n+1;
int r=rand()%n+1;
if(l>r) swap(l,r);
printf("%d %d\n",l,r);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const long long a=1e8;
int main(){
freopen("P1314.in","w",stdout);
srand(time(0));
int n=rand()%100+1,m=rand()%100+1;
long long s=(long long)rand()*rand()%a+1;
printf("%d %d %lld\n",n,m,s);
for(int i=1;i<=n;i++){
int w=(long long)rand()*rand()%10000+1;
int v=(long long)rand()*rand()%10000+1;
printf("%d %d\n",w,v);
}
for(int i=1;i<=m;i++){
int l=rand()%n+1;
int r=rand()%n+1;
if(l>r) swap(l,r);
printf("%d %d\n",l,r);
}
return 0;
}
include <bits/stdc++.h>
define int long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return xf;
}
const int N=2e5+10;
struct node{
int l,r;
}in[N];
int f,l,n,m,y[N],ans=0x3f3f3f3f3f3f3f3f,s,w[N],v[N],pre_n[N],pre_v[N],Y,sum,mn=1e15,mx=-10;
bool check(int mid){
Y=0,sum=0;
for(int i=1;i<=n;i++){
if(w[i]>=mid) pre_n[i]=pre_n[i-1]+1,pre_v[i]=pre_v[i-1]+v[i];
else pre_n[i]=pre_n[i-1],pre_v[i]=pre_v[i-1];
}
for(int i=1;i<=m;i++){
int pep=pre_n[in[i].r]-pre_n[in[i].l-1];
int val=pre_v[in[i].r]-pre_v[in[i].l-1];
Y+=pepval;
}
sum=llabs(s-Y);
if(Y>s) return 1;
else return 0;
}
signed main(){
freopen("P1314.in","r",stdin);
freopen("P1314.out","w",stdout);
n=read();m=read();s=read();
for(int i=1;i<=n;++i){
w[i]=read(),v[i]=read();
mx=max(mx,w[i]);
mn=min(mn,w[i]);
}
for(int i=1;i<=m;++i){
in[i].l=read();
in[i].r=read();
}
int l=mn-1,r=mx+2;
while(l<=r){//二分w
int mid=(l+r)>>1;
if(check(mid)) l=mid+1;
else r=mid-1;
ans=min(ans,sum);
}
cout<<ans<<endl;
return 0;
}