#include "ricehub.h"
#include <bits/stdc++.h>
// author : aykhn
using namespace std;
typedef long long ll;
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F
int besthub(int n, int L, int x[], long long b)
{
vector<int> pref(n);
pref[0] = x[0];
for (int i = 1; i < n; i++) pref[i] = pref[i - 1] + x[i];
int ans = 1;
int l = 0;
int r = 0;
for (int i = 0; i < n; i++)
{
int sum = x[i] * (i - l) - (pref[i] - (l ? pref[l - 1] : 0));
sum += pref[r] - (i ? pref[i - 1] : 0) - x[i] * (r - i);
while (l < n)
{
if (sum <= b) break;
sum -= abs(x[i] - x[l]);
l++;
}
while (r < n)
{
if (sum + x[r] - x[i] <= b)
{
sum += x[r] - x[i];
r++;
}
else break;
}
while (r < n && abs(x[l] - x[i]) > abs(x[r] - x[i]))
{
sum -= abs(x[l] - x[i]);
sum += abs(x[r] - x[i]);
l++;
r++;
}
ans = max(ans, r - l);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |