#include <iostream>
#include <vector>
using namespace std;
#define int long long
const int MAXN = 5000;
int dp[MAXN][MAXN];
int t;
bool check(int n, int k, vector <int>& a, int s) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
dp[i][j] = 0;
}
}
dp[k][k] = 1;
for (int len = 1; len <= n; ++len) {
for (int l = 0; l + len - 1 < n; ++l) {
int r = l + len - 1;
if (dp[l][r] == 0) continue;
if (r < n - 1 && (a[r + 1] - a[l] + 2 * s - 1) / (2 * s) <= (r - l + 1) * t) dp[l][r + 1] = 1;
if (l && (a[r] - a[l - 1] + 2 * s - 1) / (2 * s) <= (r - l + 1) * t) dp[l - 1][r] = 1;
}
}
return dp[0][n - 1];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k >> t; --k;
vector <int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
if (a[n - 1] == a[0]) {
cout << 0;
return 0;
}
int l = 0;
int r = a.back() - a[0];
while (r - l > 1) {
int m = (l + r) / 2;
if (check(n, k, a, m)) r = m;
else l = m;
}
cout << r;
return 0;
}
/*
3 2 50
0
200
300
3 2 10
0
200
300
20 6 1 0
2
13
27
35
46
63
74
80
88
100
101
109
110
119
138
139
154
172
192
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
41 ms |
29020 KB |
Output is correct |
23 |
Correct |
26 ms |
22876 KB |
Output is correct |
24 |
Correct |
23 ms |
29020 KB |
Output is correct |
25 |
Correct |
25 ms |
39516 KB |
Output is correct |
26 |
Correct |
60 ms |
39516 KB |
Output is correct |
27 |
Correct |
49 ms |
39516 KB |
Output is correct |
28 |
Correct |
75 ms |
39516 KB |
Output is correct |
29 |
Correct |
57 ms |
39516 KB |
Output is correct |
30 |
Correct |
56 ms |
39496 KB |
Output is correct |
31 |
Correct |
58 ms |
39516 KB |
Output is correct |
32 |
Correct |
65 ms |
39516 KB |
Output is correct |
33 |
Correct |
75 ms |
39516 KB |
Output is correct |
34 |
Correct |
45 ms |
39516 KB |
Output is correct |
35 |
Correct |
72 ms |
39516 KB |
Output is correct |
36 |
Correct |
34 ms |
39516 KB |
Output is correct |
37 |
Correct |
33 ms |
39516 KB |
Output is correct |
38 |
Correct |
61 ms |
39516 KB |
Output is correct |
39 |
Correct |
31 ms |
39516 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
41 ms |
29020 KB |
Output is correct |
23 |
Correct |
26 ms |
22876 KB |
Output is correct |
24 |
Correct |
23 ms |
29020 KB |
Output is correct |
25 |
Correct |
25 ms |
39516 KB |
Output is correct |
26 |
Correct |
60 ms |
39516 KB |
Output is correct |
27 |
Correct |
49 ms |
39516 KB |
Output is correct |
28 |
Correct |
75 ms |
39516 KB |
Output is correct |
29 |
Correct |
57 ms |
39516 KB |
Output is correct |
30 |
Correct |
56 ms |
39496 KB |
Output is correct |
31 |
Correct |
58 ms |
39516 KB |
Output is correct |
32 |
Correct |
65 ms |
39516 KB |
Output is correct |
33 |
Correct |
75 ms |
39516 KB |
Output is correct |
34 |
Correct |
45 ms |
39516 KB |
Output is correct |
35 |
Correct |
72 ms |
39516 KB |
Output is correct |
36 |
Correct |
34 ms |
39516 KB |
Output is correct |
37 |
Correct |
33 ms |
39516 KB |
Output is correct |
38 |
Correct |
61 ms |
39516 KB |
Output is correct |
39 |
Correct |
31 ms |
39516 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Execution timed out |
2259 ms |
262144 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |