#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int k; cin >> k;
int T; cin >> T; k--;
vector<int> v(n);
vector<ll> d(n);
auto check = [&](int m) {
for(int i = 0 ; i < n ; ++i)
d[i] = 2ll * T * i * m - v[i];
int pl = k, nl = k - 1;
int pr = k, nr = k + 1;
while (1) {
while (d[nl] > d[pl] && d[nl] <= d[pr] && nl > 0) nl--;
while (d[nr] < d[pr] && d[nr] >= d[pl] && nr < n - 1) nr++;
bool ok = 0;
if (nl >= 0 && d[nl] <= d[pl]) pl = nl--, ok = 1;
if (nr < n && d[nr] >= d[pr]) pr = nr++, ok = 1;
if(!ok) break;
}
if (nr < n && d[pl] > d[nr]) return false;
if (nl >= 0 && d[pr] < d[nl]) return false;
int l = 0; nl = 1;
int r = n - 1; nr = n - 2;
while (1) {
while (d[nl] > d[l] && d[nl] <= d[r] && nl < k) nl++;
while (d[nr] < d[r] && d[nr] >= d[l] && nr > k) nr--;
bool ok = 0;
if (nl <= k && d[nl] <= d[l]) l = nl++, ok = 1;
if (nr >= k && d[nr] >= d[r]) r = nr--, ok = 1;
if(!ok) break;
}
return pl <= l && r <= pr;
};
for(int&x : v)
cin >> x;
int l = 0;
int r = 1e9;
for(; l < r ;) {
int m = (l + r) / 2;
if (check(m))
r = m;
else
l = m + 1;
}
cout << l << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
236 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
236 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
320 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
324 KB |
Output is correct |
40 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
236 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
320 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
324 KB |
Output is correct |
40 |
Correct |
1 ms |
208 KB |
Output is correct |
41 |
Correct |
15 ms |
1728 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
5 ms |
720 KB |
Output is correct |
44 |
Correct |
19 ms |
2376 KB |
Output is correct |
45 |
Correct |
21 ms |
2388 KB |
Output is correct |
46 |
Correct |
21 ms |
2376 KB |
Output is correct |
47 |
Correct |
23 ms |
2360 KB |
Output is correct |
48 |
Correct |
18 ms |
2360 KB |
Output is correct |
49 |
Correct |
21 ms |
2384 KB |
Output is correct |
50 |
Correct |
18 ms |
2364 KB |
Output is correct |
51 |
Correct |
22 ms |
2372 KB |
Output is correct |
52 |
Correct |
28 ms |
2384 KB |
Output is correct |
53 |
Correct |
21 ms |
2384 KB |
Output is correct |
54 |
Correct |
17 ms |
2384 KB |
Output is correct |
55 |
Correct |
16 ms |
2504 KB |
Output is correct |
56 |
Correct |
19 ms |
2376 KB |
Output is correct |
57 |
Correct |
19 ms |
2460 KB |
Output is correct |
58 |
Correct |
21 ms |
2452 KB |
Output is correct |
59 |
Correct |
13 ms |
1624 KB |
Output is correct |
60 |
Correct |
18 ms |
2380 KB |
Output is correct |
61 |
Correct |
22 ms |
2364 KB |
Output is correct |
62 |
Correct |
24 ms |
2480 KB |
Output is correct |
63 |
Correct |
17 ms |
2448 KB |
Output is correct |
64 |
Correct |
17 ms |
2364 KB |
Output is correct |
65 |
Correct |
18 ms |
2376 KB |
Output is correct |
66 |
Correct |
17 ms |
2376 KB |
Output is correct |
67 |
Correct |
18 ms |
2452 KB |
Output is correct |
68 |
Correct |
18 ms |
2376 KB |
Output is correct |
69 |
Correct |
17 ms |
2384 KB |
Output is correct |