神一样的错误,线下运行错误,测评 40 分,求解啊
#include<cstdio>#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int n,m,l0=1,r0=0,l[200005],r[200005];
long long s,v[200005],w[200005],ans,ANS;
long f(long long W)//求Y
{
long long sumj[200005],sumv[200005];//前缀和
for(int i=0;i<=n;i++)
{sumj[i]=0;sumv[i]=0;}
for(int i=1;i<=n;i++)
{
sumj[i]=sumj[i-1];
sumv[i]=sumv[i-1];
if(w[i]>=W)
{
sumj[i]++;
sumv[i]+=v[i];
}
}
long long y=0;
for(int i=1;i<=m;i++)//Y
y+=(sumj[r[i]]-sumj[l[i]-1])*(sumv[r[i]]-sumv[l[i]-1]);
return y;
}
void ef(int l1,int r1)//被注释了
{
int t=f((l1+r1)/2);
ans=abs(s-t);
if(ans==0){ANS=0;return;}
if(ans<ANS)
{
ANS=ans;
if(s-t<0)
ef((l1+r1)/2+1,r1);
else
ef(l1,(l1+r1)/2);
}
if(l1>=r1)return;
}
int main()
{
cin>>n>>m>>s;
for(int i=1;i<=n;i++)
{
cin>>w[i]>>v[i];
if(w[i]>r0)
r0=w[i];
}
for(int i=1;i<=m;i++)
cin>>l[i]>>r[i];
//ef(l0,r0);
ANS=abs(s-f(1));
for(int i=1;i<=r0;i++)//一个个找
{
ans=abs(s-f(i));
if(ans<ANS)ANS=ans;
}
cout<<ANS;
return 0;
}
改成int得20,不报错
noip聪明的质检员