- 题解
- 2018-09-11 18:16:36 @
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200005,maxn=1000005;
long long n,m,s,w[N],v[N],l[N],r[N],f[N],g[N],ri=0,mid;
long long ans=0x3f3f3f3f3f3f;
bool check(long long W)
{
long long res=0;
for (int i=1;i<=n;i++)
{
if (w[i]>=W){
f[i]=f[i-1]+1;
g[i]=g[i-1]+v[i];
}
else{
f[i]=f[i-1];
g[i]=g[i-1];
}
}
for (int i=1;i<=m;i++)
{
int a=l[i],b=r[i];
res+=((f[b]-f[a-1])*(g[b]-g[a-1]));
}
if (ans>abs(s-res)) ans=abs(s-res);
if (s>res) return true;
return false;
}
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]>ri) ri=w[i];
}
ri++;
for (int i=1;i<=m;i++) scanf("%lld%lld",&l[i],&r[i]);
int left=0,right=ri;
while (left<right)
{
mid=(left+right)/2;
if(check(mid))
{
right=mid;
}
else left=mid+1;
}
printf("%lld\n",ans);
return 0;
}
2 条评论
-
PA_lotusbl LV 5 MOD @ 2018-10-15 19:06:11
哦啊拉拉
-
2018-09-11 18:16:45@
lalalala
- 1