#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){
int ans = 0;
int l , r;
int cnt;
int 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 = INT_MAX,dr = INT_MAX;
if(l>=0) dl= x[i]-x[l];
if(r>=0 )dr = x[r]-x[i];
if(min(dl,dr)> left)break;
if(l>= 0 && (r==0 || x[i]-x[l] <= x[r] - x[i])){
left-= dl;
l--;
}
else{
left-= dr;
r++;
}
cnt++;
}
//cout << i << " " << cnt << endl;
ans = max(ans,cnt);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |