/*input
*/
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;
template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
template<typename T>
void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
int besthub(int R, int L, int X[], ll B)
{
vl pref(R, 0);
for (int i = 0; i < R; ++i)
pref[i] = (i ? pref[i - 1] : 0) + X[i];
auto sum = [&](int a, int b) -> ll {
return pref[b] - (a ? pref[a - 1] : 0);
};
auto galima = [&](int K) -> bool {
// printf("in galima, K = %d\n", K);
for (int i = K - 1; i < R; ++i)
{
int l = i - K + 1;
int r = i;
int m = (l + r) / 2;
if (K & 1) {
ll mid = X[m];
ll reik = mid * (K / 2) - sum(l, m - 1);
reik += sum(m + 1, r) - mid * (K / 2);
// printf("i = %d, mid = %lld, reik = %lld\n", i, mid, reik);
if (reik <= B) return true;
} else {
// K = 4
// K/2 = 2
// 0 1 2 3
ll mid = (X[m] + X[m + 1]);
ll reik = mid * (K / 2) - 2 * sum(l, m);
reik += 2 * sum(m + 1, r) - mid * (K / 2);
if (reik <= 2 * B) return true;
}
}
return false;
};
int l = 1;
int h = R;
int m;
// for (int i = 0; i < R; ++i)
// printf("%d ", X[i]);
// printf("\n");
// printf("B = %lld\n", B);
while (l < h) {
m = (l + h + 1) / 2;
// printf("l = %d, m = %d, r = %d, galima = %d\n",
// l, m, h, int(galima(m)));
if (galima(m))
l = m;
else
h = m - 1;
}
return l;
}
/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 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 |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
256 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 |
256 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 |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
256 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 |
256 KB |
Output is correct |
26 |
Correct |
5 ms |
372 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 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 |
372 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
256 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 |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 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 |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
8 ms |
632 KB |
Output is correct |
3 |
Correct |
20 ms |
1528 KB |
Output is correct |
4 |
Correct |
20 ms |
1528 KB |
Output is correct |
5 |
Correct |
12 ms |
888 KB |
Output is correct |
6 |
Correct |
12 ms |
888 KB |
Output is correct |
7 |
Correct |
19 ms |
1528 KB |
Output is correct |
8 |
Correct |
18 ms |
1528 KB |
Output is correct |
9 |
Correct |
11 ms |
888 KB |
Output is correct |
10 |
Correct |
12 ms |
888 KB |
Output is correct |
11 |
Correct |
21 ms |
1528 KB |
Output is correct |
12 |
Correct |
21 ms |
1528 KB |
Output is correct |
13 |
Correct |
13 ms |
888 KB |
Output is correct |
14 |
Correct |
13 ms |
888 KB |
Output is correct |
15 |
Correct |
17 ms |
1144 KB |
Output is correct |
16 |
Correct |
18 ms |
1272 KB |
Output is correct |
17 |
Correct |
20 ms |
1400 KB |
Output is correct |
18 |
Correct |
20 ms |
1400 KB |
Output is correct |
19 |
Correct |
21 ms |
1400 KB |
Output is correct |
20 |
Correct |
21 ms |
1528 KB |
Output is correct |