#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int besthub(int R, int L, int X[], ll B) {
int lb=0, ub=0;
ll cost = 0;
vll sm; sm.push_back(0);
RE(i,R) sm.push_back(sm.back() + X[i]);
auto updateCost = [&]() {
int mid = (lb+ub)/2;
cost = 0;
// [lb,mid]
cost += (mid-lb+1)*X[mid];
cost -= sm[mid+1]-sm[lb];
// [mid,ub]
cost -= (ub-mid+1)*X[mid];
cost += sm[ub+1]-sm[mid];
};
int ans = 0;
while(lb < R) {
while(ub != R && cost < B) {
ub++;
updateCost();
}
if(cost > B) {
ub--;
updateCost();
}
ans = max(ans, ub-lb+1);
lb++;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |