#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define ld long double
#define ll long long
using namespace std;
const int N = 1e5 + 111;
const ld INF = 1e17;
int n, k;
ld T, X[N];
vector <ld> a[2], ps[2]; int mxn[2], p[2], nxt[2]; ld mn[2];
ld g(int x) {
return ps[x][p[x]];
}
void go_next(int x) {
nxt[x] = p[x] + 1;
mn[x] = INF;
while (nxt[x] <= mxn[x] && ps[x][nxt[x]] < ps[x][p[x]]) {
mn[x] = min(mn[x], ps[x][nxt[x]]);
nxt[x]++;
}
}
void set_next(int x) {
p[x] = nxt[x];
go_next(x);
}
bool check2() {
for (int i = 0; i < 2; i++) {
p[i] = nxt[i] = mn[i] = 0;
}
if (g(0) + g(1) < 0) return 0;
go_next(0);
go_next(1);
while (nxt[0] <= mxn[0] || nxt[1] <= mxn[1]) {
if (nxt[0] <= mxn[0] && mn[0] + g(1) >= 0ll) {
set_next(0);
}
else if (nxt[1] <= mxn[1] && mn[1] + g(0) >= 0) {
set_next(1);
}
else return 0;
}
return 1;
}
bool check(int s) {
a[0].clear(), a[1].clear();
a[0].pb(T);
for (int i = k + 1; i < n; i++) {
a[0].pb(-(X[i] - X[i - 1]) * 1. / (2 * s));
a[0].pb(T);
}
for (int i = k - 1; ~i; i--) {
a[1].pb(-(X[i + 1] - X[i]) * 1. / (2 * s));
a[1].pb(T);
}
ps[0].clear();
ps[1].clear();
for (int i = 0; i < 2; i++) {
ps[i].pb(0);
for (auto j: a[i]) {
ps[i].pb(ps[i].back() + j);
}
mxn[i] = max_element(all(ps[i])) - ps[i].begin();
}
bool ans = check2();
for (int i = 0; i < 2; i++) {
reverse(all(ps[i]));
mxn[i] = SZ(ps[i]) - 1 - mxn[i];
}
ans = ans & check2();
return ans;
}
void solve() {
if (X[n - 1] == 0) {
cout << 0;
return;
}
int L = 0, R = 1e9 + 1;
while (L + 1 < R) {
int m = (L + R) / 2;
if (check(m)) {
R = m;
}
else {
L = m;
}
}
cout << R;
}
void read() {
cin >> n >> k >> T;
k--;
for (int i = 0; i < n; i++) {
cin >> X[i];
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
read();
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
328 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
328 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
476 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
464 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
3 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
464 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
3 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
328 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
476 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
464 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
3 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
464 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
3 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
139 ms |
8116 KB |
Output is correct |
42 |
Correct |
5 ms |
724 KB |
Output is correct |
43 |
Correct |
39 ms |
2384 KB |
Output is correct |
44 |
Correct |
194 ms |
12896 KB |
Output is correct |
45 |
Correct |
198 ms |
10316 KB |
Output is correct |
46 |
Correct |
193 ms |
12344 KB |
Output is correct |
47 |
Correct |
203 ms |
12312 KB |
Output is correct |
48 |
Correct |
196 ms |
10824 KB |
Output is correct |
49 |
Correct |
193 ms |
12112 KB |
Output is correct |
50 |
Correct |
194 ms |
10448 KB |
Output is correct |
51 |
Correct |
198 ms |
12480 KB |
Output is correct |
52 |
Correct |
198 ms |
13300 KB |
Output is correct |
53 |
Correct |
203 ms |
13112 KB |
Output is correct |
54 |
Correct |
201 ms |
13236 KB |
Output is correct |
55 |
Correct |
193 ms |
10316 KB |
Output is correct |
56 |
Correct |
192 ms |
12756 KB |
Output is correct |
57 |
Correct |
200 ms |
13232 KB |
Output is correct |
58 |
Correct |
195 ms |
10840 KB |
Output is correct |
59 |
Correct |
12 ms |
2004 KB |
Output is correct |
60 |
Correct |
192 ms |
13252 KB |
Output is correct |
61 |
Correct |
197 ms |
13124 KB |
Output is correct |
62 |
Correct |
199 ms |
12656 KB |
Output is correct |
63 |
Correct |
188 ms |
13244 KB |
Output is correct |
64 |
Correct |
191 ms |
10092 KB |
Output is correct |
65 |
Correct |
189 ms |
10912 KB |
Output is correct |
66 |
Correct |
193 ms |
10440 KB |
Output is correct |
67 |
Correct |
194 ms |
11032 KB |
Output is correct |
68 |
Correct |
198 ms |
13156 KB |
Output is correct |
69 |
Correct |
197 ms |
13228 KB |
Output is correct |