이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)
typedef long long ll;
typedef pair < int, int > ii;
const int inf = 1e9 + 333;
const ll linf = 1e18 + inf;
const int N = 1e6 + 5;
int n;
ll m;
int a[N];
ll L[N], R[N];
int ptr;
ll getL(int i, int j) {
return (ll) (j - i + 1) * a[j] - (L[j] - L[i - 1]);
}
ll getR(int i, int j) {
return L[j] - L[i - 1] - (ll) (j - i + 1) * a[i];
}
bool check(int i, int j) {
ll need = getL(i, j);
if(need > m)
return 0;
while(ptr + 1 <= n and need + getR(j, ptr + 1) <= m)
ptr++;
return 1;
}
int solve() {
for(int i = 1; i <= n; i++)
L[i] = L[i - 1] + a[i];
for(int i = n; i >= 1; i--)
R[i] = R[i + 1] + a[i];
:: ptr = 1;
int ptr = 1, ans = 1;
for(int i = 1; i <= n; i++) {
while(ptr + 1 <= n and check(i, ptr + 1))
ptr++;
//printf("i = %d ptr = %d :: ptr = %d\n", i, ptr, :: ptr);
ans = max(ans, :: ptr - i + 1);
}
return ans;
}
int besthub(int R, int L, int X[], long long B) {
n = R;
m = B;
for(int i = 0; i < n; i++) {
a[i + 1] = X[i];
X[i] = L - X[i] + 1;
}
int ans = solve();
for(int i = 1; i <= n; i++) {
a[i] = X[n - i];
}
return max(ans, solve());
}
# | 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... |