#include <bits/stdc++.h>
//#include "ricehub.h"
using namespace std;
vector<int> v;
vector<long long> sum;
long long cost (int l, int r) {
int mij = (l + r) / 2;
return 1ll * v[mij] * (mij - l + 1) - (sum[mij] - sum[l - 1]) + (sum[r] - sum[mij - 1]) - 1ll * (r - mij + 1) * v[mij];
}
int besthub (int n, int l, int x[], long long b) {
sum.resize(n);
for (int i = 0; i < n; i++) {
sum[i] = (i ? sum[i - 1] + x[i] : x[i]);
v[i] = x[i];
}
int sol = 0;
for (int i = 0; i < n; i++) {
int st = i, dr = n - 1, ans = 0;
while (st <= dr) {
int mij = (st + dr) / 2;
if (cost(st, mij) <= b) {
ans = mij;
st = mij + 1;
}
else
dr = mij - 1;
}
sol = max(sol, ans - i + 1);
}
return sol;
}
/*int main () {
cout << besthub(5, 20, {1, 2, 10, 12, 14}, 6);
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1004 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |