orz跪求神牛改错

P1314 [NOIP2011 提高组] 聪明的质监员

star_magic_young @ 2017-11-06 22:54:39

蒟蒻死活改不出来555~

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int n,m,s;
long long ans=100000000000,xs;
long long v[200010][2],l,r,mid,ll[200010],rr[200010];
long long x[200010],ss[200010];
int main()
{
    freopen("qc.in","r",stdin);
    freopen("qc.out","w",stdout);
    cin>>n>>m>>s;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&v[i][0],&v[i][1]);
        r=max(r,v[i][0]);
    }
    for(int i=1;i<=m;i++)
        scanf("%lld%lld",&ll[i],&rr[i]);
    r++;
    ans=s;
    while(l<r)
    {
        memset(x,0,sizeof(x));
        memset(ss,0,sizeof(ss));
        mid=(l+r)/2;
        x[0]=ss[0]=1;
        //cout<<mid<<endl;
        for(int i=1;i<=n;i++)
        {    
            x[i]=x[i-1];
            ss[i]=ss[i-1];
            if(v[i][0]>=mid)
            {
                x[i]++;
                ss[i]+=v[i][1];
            }
        }
        /*for(int i=1;i<=n;i++) cout<<x[i]<<" ";
            cout<<endl;
        for(int i=1;i<=n;i++) cout<<ss[i]<<" ";
            cout<<endl;*/
        xs=0;
        for(int i=1;i<=m;i++)
            xs+=(x[rr[i]]-x[ll[i]-1])*(ss[rr[i]]-ss[ll[i]-1]);
        //cout<<xs<<endl;
        ans=min(ans,abs(s-xs));
        if(ans==0) break; 
        if(s<xs) l=mid+1;
        else r=mid;
    }
    printf("%lld\n",ans);
    return 0;
}

by 星灵王 @ 2017-11-24 19:53:26

freopen没删


by 星灵王 @ 2017-11-24 19:53:47

@ star_magic_young


by star_magic_young @ 2018-03-04 19:37:20

95分惹


|