#include "ricehub.h"
using namespace std;
#include <bits/stdc++.h>
#define ll long long
ll countPsum[100007], sumPsum[100007];
ll countrq(ll a, ll b){
if (b > a) return 0;
if (a == 0) return countPsum[b];
else return countPsum[b] - countPsum[a-1];
}
ll sumrq(ll a, ll b){
if (b > a) return 0;
if (a == 0) return sumPsum[b];
else return sumPsum[b] - sumPsum[a-1];
}
int besthub(int R, int L, int X[], long long B)
{
vector<pair<ll, ll>> vec;
for (int x = 0; x < R; x++){
if (vec.size() == 0 || vec.back().first != X[R]) vec.push_back({X[x], 1});
else vec.back().second++;
}
ll n = vec.size();
countPsum[0] = vec[0].second;
sumPsum[0] = vec[0].first * vec[0].second;
for (int x = 1; x < n; x++){
countPsum[x] = countPsum[x-1] + vec[x].second;
sumPsum[x] = sumPsum[x-1] + vec[x].first * vec[x].second;
}
int l = 0, r = 0, ans = 0;
while (r != n-1){
//calc median
int median = (l+r)/2;
ll cost = countrq(l, median-1) * vec[median].first - sumrq(l, median-1)
+ sumrq(median+1, r) - countrq(median+1, r) * vec[median].first;
;
if (cost > B) l++;
else r++, ans = max(r-l+1, ans);
}
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 |
4 ms |
1228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |