이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pf push_front
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
/*
int besthub(int n, int last, int x[], ll b){
    
    int ans = 0;
    int l , r;
    for(int i = 0; i < n; i++){
        
        l = i - (lower_bound(x.begin(), x.end(), max(0LL,x[i]-b))- x.begin());
        r =  upper_bound(x.begin(), x.end(), min((ll) last, x[i]+b)) - x.begin() - (i+1);
       // cout << x[i] << " " <<l << " " << r << endl;
        ans = max(l+r+1,ans);
    }
    
    return ans;
}
*/
int besthub(int n, int last, int x[], ll b){
    
    ll ans = 0;
    ll l , r;
    ll cnt;
    
    ll dl = 0, dr = 0;
    for(int i = 0; i < n; i++){
        cnt = 1;
        ll left = b;
        
        l = i-1,r = i+1;
        while( (l >= 0 || r<n)){
            dl = LLONG_MAX,dr = LLONG_MAX;
            if (l>=0) dl= x[i]-x[l];
            if (r<n) dr = x[r]-x[i];
           // cout << x[i] << " " << l << " " << r<< endl;
            if(l>= 0 && (r>=n || dl <= dr)){
                if(left<dl) break;
                left-= dl;
                l--;
            }
            else{   
                if(left<dr) break;
                left-= dr;
                r++;
            } 
            cnt++;
        }
        ans = max(ans,cnt);
    }
    
    return ans;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |