#include <bits/stdc++.h>
#include "ricehub.h"
#define sz(s) (int)s.size()
using namespace std;
#define ll long long
vector <int> v;
bool f(int x, ll b, int n){
ll k = 0, ind = x/2, in = x-1;
for(int i = 0; i < in; i++){
k += abs(v[ind]-v[i]);
}
while(in < n){
k += abs(v[in]-v[ind]);
if(k <= b) return true;
k -= (in-ind)*(v[ind+1]-v[ind]);
k -= (ind-in-x+2)*(v[ind]-v[ind-1]);
k -= (v[in-x+1]);
in++;
ind++;
}
return false;
}
int besthub(int n, int L, int a[], ll b){
for(int i = 0; i < n; i++) v.push_back(a[i]);
int l = 2, r = n, ans = 1;
while(l <= r){
int md = (l + r) / 2;
if(f(md,b,n) == 1){
l = md+1;
ans = md;
}
else {
r = md-1;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |