이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;
ll a[1000005];
ll l[1000005];
bool can(int i, int j, ll b) {
int mid = (i+j)/2;
ll left = (mid-i+1)*a[mid] - (l[mid]-l[i-1]);
ll right = l[j]-l[mid-1] - (j-mid+1)*a[mid];
return left+right <= b;
}
ll besthub(int r, int L, int x[], ll b) {
int maxlen = -1;
for(int i = 0; i < r; i++) a[i+1] = x[i];
for(int i = 1; i <= r; i++) l[i] = l[i-1] + a[i];
int ptr = 1;
for(int i = 1; i <= r; i++) {
ptr = max(i, ptr);
while(ptr+1 <= r && can(i, ptr+1, b)) ptr++;
maxlen = max(maxlen, ptr-i+1);
}
return maxlen;
}
/*
int main()
{
int x[1] = {1};
cout << besthub(1, 20, x, 6) << endl;
return 0;
}*/
# | 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... |