安子 @ 2020-07-31 18:46:06
全WA
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f3f
using namespace std;
struct qc{
int vi;
int wi;
}a[200010];
struct qj{
int le,ri;
}b[200010];
ll num[200010];
ll tot[200010];
ll n,m,S,Y,W;
ll minans=inf;
int firstw=-1;
void findans(int l,int r)
{
while(l<=r)
{
memset(num, 0, sizeof(num));
memset(tot, 0, sizeof(tot));
int middle=(l+r)/2;Y=0;
for (int i=1;i<=n;++i)
{
if (a[i].wi>=middle)
num[i]=num[i-1]+1,tot[i]=tot[i-1]+a[i].vi;
else num[i]=num[i-1],tot[i]=tot[i-1];
}
for (int i=1;i<=m;++i)
Y+=(num[b[i].ri]-num[b[i].le-1])*(tot[b[i].ri]-tot[b[i].le-1]);
if (abs(S-Y)<minans)
{
l=m+1;minans=abs(S-Y);
}
else r=m-1;
}
}
int main()
{
scanf("%d%d%lld",&n,&m,&S);
for (int i=1;i<=n;++i)
scanf("%d%d",&a[i].wi,&a[i].vi),firstw=max(a[i].wi,firstw);
for (int i=1;i<=m;++i) scanf("%d%d",&b[i].le,&b[i].ri);
findans(1,firstw+1);
cout<<minans<<endl;
return 0;
}