#include "ricehub.h"
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int besthub(int R, int L, int X[], long long B) {
vector<ll> ps(R);
ps[0] = X[0];
for (int i = 1; i < R; i++) {
ps[i] = ps[i - 1] + ll(X[i]);
}
int en = 0;
int ans = 0;
for (int st = 0; st < R; st++) {
if (en < st) en = st;
for (; en < R - 1;) {
int mid = (en + 1 - st) / 2;
ll lo = ps[mid] - (st == 0 ? 0 : ps[st - 1]);
ll hi = ps[en] - ps[mid];
ll cost = (mid - st + 1) * ll(X[mid]) - lo + hi -
(en + 1 - mid) * ll(X[mid]);
// cout << "cost " << st << " " << (en + 1) << " " << cost << "\n";
// cout << (mid - lo + 1) << " " << (en + 1 - mid) << " " << X[mid]
// << "\n";
if (cost <= B)
en++;
else
break;
}
ans = max(ans, en - st + 1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |