40分求解??
查看原帖
40分求解??
903196
李逸扬2013楼主2024/5/3 19:12
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
long long t,n,v,ans;
long long x[50001];
bool com(int a,int b){
    return a>b;
}
bool cmp(int a,int b){
    return a<b;
}
void chushi(){
    scanf("%ld %ld",&t,&n);
    for(int i = 1;i<=n;i++){
        scanf("%ld",&x[i]);
    }
    sort(x+1,x+1+n);
    v = lower_bound(x+1,x+1+n,0)-(x+1);
}
void chuli(){
    for(long long i = 0;(0-x[v-i])<=t&&i<v;i++){
        long long a = t-(0-x[v-i])*2;
        if(a<=0){
            ans = max(ans,i);
        }
        else{
            long long b = lower_bound(x+v+1,x+n+1,a)-(x+v);
            if(x[b+1+v] == a){
                ans = max(ans,i+b+1);
            }
            else{
                ans = max(ans,b+i);
            }
        }
    }
}

int main(){
    chushi();
    chuli();
    if(x[v+2] == 0) ans++;
    cout<<ans<<endl;
    return 0;
}

只得40分??

2024/5/3 19:12
加载中...