// O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
#include <cassert>
// #include "grader.h"
using namespace std;
#define ll long long
#define ld double
#define null NULL
#define prev prev228
#define index index228
#define left left228
#define right right228
#define hash hash228
#define y1 y1228
#define firn(i, n) for (int i = 0; i < (int)n; ++i)
#define forn(i, n) for (int i = 1; i <= (int)n; ++i)
#define endl '\n'
template<typename T> void uin(T &a, T b) {
if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
if (b > a) a = b;
}
const int N = 100 * 1000 + 228;
long long sum[N];
int x[N];
long long f(int l, int r, int i) {
long long res = 0LL;
res += (sum[r] - sum[i]) - (long long)x[i - 1] * (long long)(r - i);
res += (long long)x[i - 1] * (long long)(i - l) - (sum[i - 1] - sum[l - 1]);
return res;
}
int besthub(int n, int L, int X[], long long B){
for (int i = 0; i < n; ++i) {
x[i] = X[i];
}
for (int i = 1; i <= n; ++i) {
sum[i] = sum[i - 1] + x[i - 1];
}
int k = 1;
for (int i = 1; i <= n; ++i) {
int l = i - k / 2, r = i + k / 2;
if (l < 1 || r > n) continue;
while (l > 1 && r < n && f(l - 1, r + 1, i) <= B) {
--l;
++r;
}
if (f(l, r, i) <= B) {
uax(k, r - l + 1);
}
if (r < n && f(l, r + 1, i) <= B) uax(k, r - l + 2);
if (l > 1 && f(l - 1, r, i) <= B) uax(k, r - l + 2);
}
return k;
}
// int X[N];
// signed main() {
// X[0] = 1, X[1] = 2, X[2] = 10, X[3] = 12, X[4] = 14;
// cout << besthub(5, 20, X, 6LL) << '\n';
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
380 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
408 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
7 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
380 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
572 KB |
Output is correct |
2 |
Correct |
8 ms |
632 KB |
Output is correct |
3 |
Correct |
23 ms |
1912 KB |
Output is correct |
4 |
Correct |
24 ms |
2936 KB |
Output is correct |
5 |
Correct |
13 ms |
1528 KB |
Output is correct |
6 |
Correct |
14 ms |
1272 KB |
Output is correct |
7 |
Correct |
23 ms |
2680 KB |
Output is correct |
8 |
Correct |
21 ms |
2680 KB |
Output is correct |
9 |
Correct |
13 ms |
1400 KB |
Output is correct |
10 |
Correct |
13 ms |
1400 KB |
Output is correct |
11 |
Correct |
28 ms |
2936 KB |
Output is correct |
12 |
Correct |
26 ms |
2936 KB |
Output is correct |
13 |
Correct |
15 ms |
1528 KB |
Output is correct |
14 |
Correct |
14 ms |
1528 KB |
Output is correct |
15 |
Correct |
20 ms |
2296 KB |
Output is correct |
16 |
Correct |
20 ms |
2296 KB |
Output is correct |
17 |
Correct |
23 ms |
2680 KB |
Output is correct |
18 |
Correct |
24 ms |
2680 KB |
Output is correct |
19 |
Correct |
25 ms |
2808 KB |
Output is correct |
20 |
Correct |
28 ms |
2808 KB |
Output is correct |