有点问题

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

gunners_in_code @ 2023-12-24 19:05:37

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N =200010;
ll n,m,s;
ll st[N],en[N],tw[N],tv[N],maxnum=0,w[N],v[N];
ll caculate(ll mid){
    for(int i=1;i<=n;i++){
        if(w[i]>=mid) tw[i]=tw[i-1]+1,tv[i]=tv[i-1]+v[i]; 
        else tw[i]=tw[i-1],tv[i]=tv[i-1];
    }
    ll res=0;
    for(int i=1;i<=m;i++){
        res+=(tw[en[i]]-tw[st[i]-1])*(tv[en[i]]-tv[st[i]-1]);
    }
    return res;
}
int main(){
    scanf("%lld%lld%lld",&n,&m,&s);
    for (int i = 1; i <=n; i++)
    {
        scanf("%lld%lld",&w[i],&v[i]);
        maxnum=max(maxnum,w[i]);
    }
    for (int i = 1; i <=m; i++)
    {
        scanf("%lld%lld",&st[i],&en[i]);
    }
    ll l=0,r=maxnum,mid,res,minnum=1e15;
    while(l<r){
        mid=(l+r)>>1;
        res=caculate(mid);
        ll tt=s-res;
        if(0>=tt) l=mid+1;
        else r=mid;
        minnum=min(minnum,abs(tt));
    }
    printf("%lld",minnum);
    return 0;
} 

为什么上面判断条件的时候我写>=第13个点过不了写>就可以过了?题意不是>吗?


by ax_by_c @ 2023-12-24 19:39:41

<<我写>=第13个点过不了写>就可以过了?题意不是>吗?>>


by _qingshu_ @ 2023-12-24 19:50:51


by _anll_ @ 2023-12-24 19:53:00

视力最高的一集


by Caiest_Oier @ 2023-12-24 21:19:24

视力最高的一集


by gunners_in_code @ 2023-12-25 16:34:28

为什么我没瞎吧?在caculate函数里面的if(w[i]>=mid)这里不是 w j ​ ≥W吗?


|