求助《关于我的代码LOJ上AC而洛谷WA这件事》

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

Unknnownnn @ 2022-07-22 10:46:59

https://loj.ac/s/1524781 https://www.luogu.com.cn/record/80658222

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200010;
ll n,m,s,w[N],v[N],l[N],r[N],W,pren[N],pres[N];
ll check(ll x){
    ll ans=0;
    memset(pren,0,sizeof(pren));
    memset(pres,0,sizeof(pres));
    for(int i=1;i<=n;++i)
        if(w[i]>=x)pren[i]=pren[i-1]+1,pres[i]=pres[i-1]+v[i];
        else pren[i]=pren[i-1],pres[i]=pres[i-1];
    for(int i=1;i<=m;++i)
        ans+=(pren[r[i]]-pren[l[i]-1])*(pres[r[i]]-pres[l[i]-1]);
    return s-ans;
}
int main(){
//  freopen("qc.in","r",stdin);
//  freopen("qc.out","w",stdout);
    scanf("%lld%lld%lld",&n,&m,&s);
    for(int i=1;i<=n;++i){
        scanf("%lld%lld",&w[i],&v[i]);
        W=max(W,w[i]);
    }
    for(int i=1;i<=m;++i){
        scanf("%lld%lld",&l[i],&r[i]);
    }
    ll L=1,R=W+2,tmp;
    while(L<R){
        ll mid=L+R>>1,t=check(mid);
        tmp=min(tmp,llabs(t));
        if(t>0)R=mid;
        else L=mid+1;
    }
    printf("%lld",tmp);
//  fclose(stdin);fclose(stdout);
    return 0;
}

by Unknnownnn @ 2022-07-22 11:22:47

没事了我的问题


by dream0330 @ 2022-08-11 11:52:12

emmm


by _wakeup @ 2022-11-09 22:05:52

az....


|