This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#include "ricehub.h"
int N, M, K, ans;
int cnt[100010], pre[100010];
vector<int> A;
int sum(int lx, int rx) {
return pre[rx] - pre[lx - 1];
}
bool check(int lx, int rx) {
int x = A[(rx + lx + 1) / 2];
auto it1 = lower_bound(A.begin() + lx, A.begin() + rx + 1, x);
auto it2 = upper_bound(A.begin() + lx, A.begin() + rx + 1, x);
int small = 0, big = 0;
if (it1 != A.begin()) --it1, small = (it1 - A.begin()) - lx + 1;
if (it2 != A.end()) big = rx - (it2 - A.begin()) + 1;
int cost = x * (small - big) - (sum(lx, (it1 - A.begin())) - sum((it2 - A.begin()), rx));
return cost <= K;
}
int besthub(int R, int L, int X[], long long B)
{
N = R; M = L; K = B;
A.resize(N + 1);
for (int i = 1; i <= N; ++i) {
A[i] = X[i - 1];
++cnt[A[i]];
pre[i] = pre[i - 1] + A[i];
}
int rx = 1;
for (int i = 1; i <= N; ++i) {
while (rx <= N && check(i, rx)) ++rx;
if (rx > N) break;
ans = max(ans, rx - i + 1);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |